admin管理员组文章数量:1431788
I have an application written with Spring Boot and JS on client. All JS & CSS code is stored in src/main/webapp
and piled with Webpack to the same directory. It seems dirty to put piled bundle there, but I wonder if there's a way to store it in build directory?
I've managed to add it to war file using the next code in build.gradle
from("${buildDir}") {
include 'bundle.js'
}
But I have no sense how to achieve the same effect for bootRun task or in Intellij Idea.
Also, how I can exclude source files stored in src/main/webapp/js
and src/main/webapp/scss
? And what best practices exists for managing web assets?
I have an application written with Spring Boot and JS on client. All JS & CSS code is stored in src/main/webapp
and piled with Webpack to the same directory. It seems dirty to put piled bundle there, but I wonder if there's a way to store it in build directory?
I've managed to add it to war file using the next code in build.gradle
from("${buildDir}") {
include 'bundle.js'
}
But I have no sense how to achieve the same effect for bootRun task or in Intellij Idea.
Also, how I can exclude source files stored in src/main/webapp/js
and src/main/webapp/scss
? And what best practices exists for managing web assets?
2 Answers
Reset to default 1You should probably take a look at Jhipster (http://jhipster.github.io/)
BTW, for my projects, I clearly prefer to separate client code from server code. A 'project-client' directory for JS code, next to the 'project-server' directory with Java code.
The former one has obviously a "standard Java" files structure.
For the first one, JS has now its own standards. Ok, they're yet not very stable ;), but still. Your JS source code can be half - or more - of your source, its place is probably not in a subdirectory of your Java project...
Moreover, tools like Webpack are very powerful. Webpack can embed styles, images or other resources when it's relevant. The source files / resources files / build product files should be as clearly separated as in your Java project.
When developing, use webpack server. My index.html host page (deserved by the Java server) simply points to localhost:[webpack-port]/main.js
Then there's the question of the global build, which is easily resolved with Gradle. Gradle calls NPM (thanks to https://github./srs/gradle-node-plugin) to test and build the JS part, then it builds the Java part. It finally copies the final jar and the javascript files in a final and global build directory. The name of the JS files - which contains a hash, you should keep that powerful feature ! - are given to a conf file which is used by the Java application.
I had struggled a lot to find a solution to exclude node_modules in my webapp. I added following block in my build.gradle
sourceSets {
main {
resources {
exclude '**/node_modules'
}
}
}
Hope it helps.
本文标签: javascriptSpring Boot with Gradle and WebpackStack Overflow
版权声明:本文标题:javascript - Spring Boot with Gradle and Webpack - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745484993a2660341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论