Selaa lähdekoodia

First "working" version of the store: Correctly bundle the dist/ folder, so that Spring can handle that.
The remaining issue revolves around jQuery and it's need to be in the window scope, as it's required by a few libraries:
See the inline requires in test.html, that code will, after bundling, contain the whole jQuery code.
Just requiring jQuery in a referenced js file (e.g. test.js) doesn't seem to load it properly/it's stripped off?
That situation is however not desirable (slamming lots of javascript code inline into html) and also causes issues with the html template system.
That's why in this case `semantic.min.js` has been moved from the layout (where it would belong) into the individual page for now.
Caution: Expect ammend commits / force pushes.

MeFisto94 4 vuotta sitten
vanhempi
commit
b09c53af81

+ 4 - 2
src/main/java/com/jayfella/website/config/ResourcesConfig.java

@@ -33,7 +33,7 @@ public class ResourcesConfig implements WebMvcConfigurer {
                 )
                 .setCacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES));*/
 
-        registry.addResourceHandler("**").addResourceLocations("file:./www/dist/")
+        /*registry.addResourceHandler("**").addResourceLocations("file:./www/dist/")
                 .setCacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES))
                 .resourceChain(true)
                 .addResolver(new PathResourceResolver());
@@ -41,7 +41,9 @@ public class ResourcesConfig implements WebMvcConfigurer {
         registry.addResourceHandler(".*").addResourceLocations("file:./www/dist/")
                 .setCacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES))
                 .resourceChain(true)
-                .addResolver(new PathResourceResolver());
+                .addResolver(new PathResourceResolver());*/
+        registry.addResourceHandler("/static/**").addResourceLocations("file:./www/dist/static/")
+                .setCacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES));
 
     }
 

+ 4 - 0
www/.parcelrc

@@ -0,0 +1,4 @@
+{
+  "extends": "@parcel/config-default",
+  "namers": [ "parcel-namer-rewrite" ]
+}

+ 0 - 1
www/index.html

@@ -6,7 +6,6 @@
     <link rel="stylesheet" href="./libs/semantic/dist/semantic.css" />
 	<link rel="stylesheet" href="/src/css/store-index.css" />
 	<script src="/src/js/test.js" defer></script>
-
 </head>
 
 <body>

+ 9 - 6
www/layout/layout.html

@@ -3,11 +3,17 @@
 
 <head>
 	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
-
 	<title layout:title-pattern="$CONTENT_TITLE - $LAYOUT_TITLE" th:text="${pageTitle}"></title>
 
 	<link rel="shortcut icon" type="image/icon" href="../favicon.ico" />
 
+    <link rel="stylesheet" type="text/css" href="/src/css/style.css" />
+    <link rel="stylesheet" type="text/css" href="../libs/semantic/dist/semantic.min.css" />
+
+    <script>
+        $ = require( "jquery" );
+    </script>
+
 	<!-- Global site tag (gtag.js) - Google Analytics -->
 	<script async src="https://www.googletagmanager.com/gtag/js?id=UA-143545224-1"></script>
 	<script>
@@ -20,12 +26,9 @@
 
 		gtag("config", "UA-143545224-1");
 	</script>
+    <!-- <script src="../libs/semantic/dist/semantic.min.js"></script> -->
+    <script src="../libs/moment/2.24.0/moment.min.js"></script>
 
-	<link rel="stylesheet" type="text/css" href="/src/css/style.css" />
-	<link rel="stylesheet" type="text/css" href="../libs/semantic/dist/semantic.min.css" />
-
-	<script src="../libs/semantic/dist/semantic.min.js"></script>
-	<script src="../libs/moment/2.24.0/moment.min.js"></script>
 
 	<script src="/src/js/page-api.js"></script>
 

+ 5 - 0
www/package-lock.json

@@ -6555,6 +6555,11 @@
       "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz",
       "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw=="
     },
+    "jquery-ui": {
+      "version": "1.12.1",
+      "resolved": "https://registry.npmjs.org/jquery-ui/-/jquery-ui-1.12.1.tgz",
+      "integrity": "sha1-vLQEXI3QU5wTS8FIjN0+dop6nlE="
+    },
     "js-beautify": {
       "version": "1.14.0",
       "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.14.0.tgz",

+ 12 - 4
www/package.json

@@ -5,7 +5,7 @@
   "private": true,
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1",
-    "parcel": "parcel build [!node_modules]**/*.html *.html layout/layout.html error/*.html",
+    "parcel": "parcel build --log-level verbose \"[!node_modules]**/*.html\" \"*.html\" \"layout/layout.html\" \"error/*.html\"",
     "parcelServe": "parcel serve [!node_modules]**/*.html *.html layout/layout.html error/*.html"
   },
   "author": "",
@@ -15,6 +15,7 @@
     "fomantic-ui": "^2.8.8",
     "highlight.js": "^9.15.10",
     "jquery": "^3.6.0",
+    "jquery-ui": "^1.12.1",
     "markdown-it": "^10.0.0",
     "markdown-it-abbr": "^1.0.4",
     "markdown-it-deflist": "^2.0.3",
@@ -40,9 +41,16 @@
   "parcel-namer-rewrite": {
     "chain": "@parcel/namer-default",
     "rules": {
-      "src/css/(.*).css": "css/$1{.hash}.css",
-      "src/js/(.*).js": "css/$1{.hash}.js",
-      "src/js/test.js": "js/test{hash}.js"
+      "(.*).js": "static/js/$1.js",
+      "(.*).css": "static/css/$1.css",
+      "(.*).png": "static/images/$1.png",
+      "(.*).gif": "static/images/$1.gif",
+      "(.*).ico": "static/images/$1.ico",
+      "(.*).svg": "static/images/$1.svg",
+      "(.*).ttf": "static/fonts/$1.ttf",
+      "(.*).eot": "static/fonts/$1.eot",
+      "(.*).woff": "static/fonts/$1.woff",
+      "(.*).woff2": "static/fonts/$1.woff2"
     }
   }
 }

+ 2 - 0
www/src/js/common.js

@@ -1,3 +1,5 @@
+$ = require('jquery');
+
 $("#sideMenuButton, #closeSideMenuButton").click(function() {
 	$(".ui.sidebar")
 		.sidebar("setting", "transition", "overlay")

+ 13 - 4
www/test.html

@@ -2,13 +2,22 @@
 <html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{layout/layout}">
 	<head>
 		<title>View Page</title>
-        <link rel="stylesheet" href="./libs/semantic/dist/semantic.css" />
+        <script>
+            $ = require("jquery");
+            jQuery = $;
+            require("jquery-ui");
+            require("blueimp-gallery"); // CSS?
+        </script>
+        <script src="/libs/semantic/dist/semantic.min.js"></script>
+        <script src="/src/js/test.js" defer></script>
+        <script src="/src/js/view-page.js" defer></script>
+
+        <!-- <link rel="stylesheet" href="./libs/semantic/dist/semantic.css" /> -->
         <link rel="stylesheet" href="/node_modules/blueimp-gallery/css/blueimp-gallery.css" />
         <link rel="stylesheet" href="/src/css/view-page.css" />
 
-        <script src="/node_modules/blueimp-gallery/js/blueimp-gallery.js"></script>
-        <script src="/src/js/test.js" defer></script>
-        <script src="/src/js/view-page.js" defer></script>
+        <!-- <script src="/node_modules/blueimp-gallery/js/blueimp-gallery.js"></script> -->
+
 
 		<meta th:if="${preview != null && preview == false}" property="og:title" th:content="${previewTitle}">
 		<meta th:if="${preview != null && preview == false}" property="og:description" th:content="${previewDescription}">

+ 2 - 3
www/view-page.html

@@ -4,12 +4,11 @@
 <head>
 	<title>View Page</title>
 
-	<link rel="stylesheet" href="/libs/blueimp-gallery/2.33.0/css/blueimp-gallery.min.css" />
+    <link rel="stylesheet" href="/node_modules/blueimp-gallery/css/blueimp-gallery.css" />
 	<!-- <link rel="stylesheet" href="url(/libs/highlightjs/9.15.10/styles/monokai-sublime.css" /> -->
 	<link rel="stylesheet" href="/src/css/view-page.css" />
 
-	<script src="./libs/blueimp-gallery/2.41.0/js/blueimp-gallery.min.js"></script>
-
+    <script src="/node_modules/blueimp-gallery/js/blueimp-gallery.js"></script>
     <script src="/src/js/view-page.js" defer></script>
 
 	<meta th:if="${preview != null && preview == false}" property="og:title" th:content="${previewTitle}">