From c35f171d321aa8fcc57a229c47fe8db7d812b340 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Sun, 26 Jul 2020 20:55:39 +1000 Subject: [PATCH] refactor to package the Vue components into the JAR instead of copying files around --- spring-boot/thymeleaf-vue/client/build.gradle | 24 +++++++++++++++++-- spring-boot/thymeleaf-vue/client/package.json | 1 + spring-boot/thymeleaf-vue/server/build.gradle | 17 ++----------- .../thymeleafvue/HelloVueController.java | 2 +- .../main/resources/templates/hello-vue.html | 2 +- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/spring-boot/thymeleaf-vue/client/build.gradle b/spring-boot/thymeleaf-vue/client/build.gradle index 5305078..74ffbb2 100644 --- a/spring-boot/thymeleaf-vue/client/build.gradle +++ b/spring-boot/thymeleaf-vue/client/build.gradle @@ -2,8 +2,28 @@ plugins { id "com.github.node-gradle.node" version "2.2.4" } -task build(type: NpmTask) { +apply plugin: 'java' + +group = 'io.reflectoring' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '11' + +task npmBuild(type: NpmTask) { inputs.dir("src") outputs.dir("dist") args = ['run', 'build'] -} \ No newline at end of file +} + +task npmClean(type: NpmTask) { + args = ['run', 'clean'] +} + +jar { + into '/static', { + from 'dist' + include '**/*.umd.min.js' + } +} + +jar.dependsOn('npmBuild') +clean.dependsOn('npmClean') \ No newline at end of file diff --git a/spring-boot/thymeleaf-vue/client/package.json b/spring-boot/thymeleaf-vue/client/package.json index 51345a3..041fe25 100644 --- a/spring-boot/thymeleaf-vue/client/package.json +++ b/spring-boot/thymeleaf-vue/client/package.json @@ -5,6 +5,7 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build --target lib --dest dist/WeekChart --name WeekChart src/components/WeekChart.vue", + "clean": "rm -rf dist", "lint": "vue-cli-service lint", "storybook": "start-storybook -p 6006", "build-storybook": "build-storybook", diff --git a/spring-boot/thymeleaf-vue/server/build.gradle b/spring-boot/thymeleaf-vue/server/build.gradle index 4082652..1a10270 100644 --- a/spring-boot/thymeleaf-vue/server/build.gradle +++ b/spring-boot/thymeleaf-vue/server/build.gradle @@ -6,14 +6,14 @@ plugins { group = 'io.reflectoring' version = '0.0.1-SNAPSHOT' -sourceCompatibility = '1.8' +sourceCompatibility = '11' repositories { mavenCentral() } dependencies { - project(':client') + implementation project(':client') implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation('org.springframework.boot:spring-boot-starter-test') { @@ -24,16 +24,3 @@ dependencies { test { useJUnitPlatform() } - -task copyJavascriptComponents(type: Copy) { - from '../client/dist' - include '**/*.umd.min.js' - into 'src/main/resources/static/js/vue-components' -} - -task cleanJavascriptComponents(type: Delete) { - delete 'src/main/resources/static/js/vue-components' -} - -processResources.dependsOn copyJavascriptComponents -clean.dependsOn cleanJavascriptComponents diff --git a/spring-boot/thymeleaf-vue/server/src/main/java/io/reflectoring/thymeleafvue/HelloVueController.java b/spring-boot/thymeleaf-vue/server/src/main/java/io/reflectoring/thymeleafvue/HelloVueController.java index 1285c48..f079bb7 100644 --- a/spring-boot/thymeleaf-vue/server/src/main/java/io/reflectoring/thymeleafvue/HelloVueController.java +++ b/spring-boot/thymeleaf-vue/server/src/main/java/io/reflectoring/thymeleafvue/HelloVueController.java @@ -11,7 +11,7 @@ import java.util.Map; @Controller class HelloVueController { - @GetMapping("/hello") + @GetMapping("/") ModelAndView showHelloPage() { Map model = new HashMap<>(); model.put("title", "Hello Vue!"); diff --git a/spring-boot/thymeleaf-vue/server/src/main/resources/templates/hello-vue.html b/spring-boot/thymeleaf-vue/server/src/main/resources/templates/hello-vue.html index d0bffc6..50b7bbf 100644 --- a/spring-boot/thymeleaf-vue/server/src/main/resources/templates/hello-vue.html +++ b/spring-boot/thymeleaf-vue/server/src/main/resources/templates/hello-vue.html @@ -8,7 +8,7 @@ - +