Skip to content

Commit c35f171

Browse files
committed
refactor to package the Vue components into the JAR instead of copying files around
1 parent 44fe1a4 commit c35f171

5 files changed

Lines changed: 27 additions & 19 deletions

File tree

spring-boot/thymeleaf-vue/client/build.gradle

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,28 @@ plugins {
22
id "com.github.node-gradle.node" version "2.2.4"
33
}
44

5-
task build(type: NpmTask) {
5+
apply plugin: 'java'
6+
7+
group = 'io.reflectoring'
8+
version = '0.0.1-SNAPSHOT'
9+
sourceCompatibility = '11'
10+
11+
task npmBuild(type: NpmTask) {
612
inputs.dir("src")
713
outputs.dir("dist")
814
args = ['run', 'build']
9-
}
15+
}
16+
17+
task npmClean(type: NpmTask) {
18+
args = ['run', 'clean']
19+
}
20+
21+
jar {
22+
into '/static', {
23+
from 'dist'
24+
include '**/*.umd.min.js'
25+
}
26+
}
27+
28+
jar.dependsOn('npmBuild')
29+
clean.dependsOn('npmClean')

spring-boot/thymeleaf-vue/client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"serve": "vue-cli-service serve",
77
"build": "vue-cli-service build --target lib --dest dist/WeekChart --name WeekChart src/components/WeekChart.vue",
8+
"clean": "rm -rf dist",
89
"lint": "vue-cli-service lint",
910
"storybook": "start-storybook -p 6006",
1011
"build-storybook": "build-storybook",

spring-boot/thymeleaf-vue/server/build.gradle

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ plugins {
66

77
group = 'io.reflectoring'
88
version = '0.0.1-SNAPSHOT'
9-
sourceCompatibility = '1.8'
9+
sourceCompatibility = '11'
1010

1111
repositories {
1212
mavenCentral()
1313
}
1414

1515
dependencies {
16-
project(':client')
16+
implementation project(':client')
1717
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
1818
implementation 'org.springframework.boot:spring-boot-starter-web'
1919
testImplementation('org.springframework.boot:spring-boot-starter-test') {
@@ -24,16 +24,3 @@ dependencies {
2424
test {
2525
useJUnitPlatform()
2626
}
27-
28-
task copyJavascriptComponents(type: Copy) {
29-
from '../client/dist'
30-
include '**/*.umd.min.js'
31-
into 'src/main/resources/static/js/vue-components'
32-
}
33-
34-
task cleanJavascriptComponents(type: Delete) {
35-
delete 'src/main/resources/static/js/vue-components'
36-
}
37-
38-
processResources.dependsOn copyJavascriptComponents
39-
clean.dependsOn cleanJavascriptComponents

spring-boot/thymeleaf-vue/server/src/main/java/io/reflectoring/thymeleafvue/HelloVueController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Controller
1212
class HelloVueController {
1313

14-
@GetMapping("/hello")
14+
@GetMapping("/")
1515
ModelAndView showHelloPage() {
1616
Map<String, Object> model = new HashMap<>();
1717
model.put("title", "Hello Vue!");

spring-boot/thymeleaf-vue/server/src/main/resources/templates/hello-vue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h1 th:text="${title}">This title will be replaced</h1>
88
</div>
99

1010
<script src="https://unpkg.com/vue"></script>
11-
<script th:src="@{/js/vue-components/WeekChart/WeekChart.umd.min.js}"></script>
11+
<script th:src="@{/WeekChart/WeekChart.umd.min.js}"></script>
1212
<script>
1313
(function() {
1414
new Vue({

0 commit comments

Comments
 (0)