Closed rvplogu closed 4 years ago
Also experiencing this.
Steps to reproduce
git clone https://github.com/spring-guides/tut-react-and-spring-data-rest.git
basic
project with spring-boot:run
via IntelliJ Ideahttp://localhost:8080/
. App works.npm run-script watch
in the basic
directory. Watching starts OK.app.js
and save it. Watch triggers.http://localhost:8080/
and hard-refresh the page. Changes from the previous step don't appear.Expected behavior Changes appear.
Platform Windows 10
Additional details Here's the watch output:
Hash: d393da15462f9a854f4f
Version: webpack 4.41.5
Time: 120ms
Built at: 2019-12-29 22:15:18
Asset Size Chunks Chunk Names
./src/main/resources/static/built/bundle.js 3.13 MiB main [emitted] main
Entrypoint main = ./src/main/resources/static/built/bundle.js
[./src/main/js/app.js] 4.82 KiB {main} [built]
+ 60 hidden modules
The changes do show up in ./src/main/resources/static/built/bundle.js
, but they don't show up in the bundle.js
unless I stop & start the server.
Seemed to find a potential fix:
In package.json
, change "watch": "webpack --watch -d"
to
"watch": "webpack --watch -d --output ./target/classes/static/built/bundle.js"
After doing that, restarting the server & running npm run-script watch
, the changes are immediately reflected when editing app.js.
Details
Looks like there are two bundle.js
files:
src/main/resources/static/built/bundle.js
target/classes/static/built/bundle.js
The webpack.config.js
directs the output to file 1, which I guess gets copied to file 2. when the project is built.
Without the change mentioned above, npm run-script watch
updates file 1. Because Spring Boot serves file 2, the updates aren't reflected in the UI.
Next steps? Unless someone comes up with a better fix, I'll PR this one.
I'm wondering if webpack.config.js
could be changed to direct the output to ./target/classes/static/built/bundle.js
instead of './src/main/resources/static/built/bundle.js'
(would remove the need for watch output configuration). But I don't know if that would work, haven't tested it.
If you're not using an IDE (which it looks you ARE), and using ./mvnw spring-boot:run
I found after digging for a bit that this is the correct answer: enabling addResources
see https://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html#Running_the_application
https://stackoverflow.com/questions/24762657/refreshing-static-content-with-spring-mvc-and-boot
However, you might need an IDE specific answer for Eclipse.
Hi, I run my application file and also run
npm run watch
command. If I do any modification in js file it is not reflected in browser. Can someone suggest me for this?