Webpacker公用/资产中的文件速度慢且重复



使用Rails/Webpacker编译资产。

Webpacker开始变得非常慢(编译时间为3分钟(。我注意到public/assets文件夹中充满了像..这样的指印资产。。

application-1e69eb85a81f4a963fde.jsapplication-828cf61e1e6dc295ffee.jsapplication-95ba1bc02eaf571bca3d.js

每次刷新页面都会创建新的。

我在开发模式下启动服务器,我不知道为什么每次刷新都会产生一个新的指印资产。但我猜这就是问题的原因。

有人经历过这种情况吗?

webpack.yml

# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: client
source_entry_path: bundles
public_output_path: assets/bundles # outputs to => public/assets/bundles
cache_path: tmp/cache/webpacker
cache_manifest: false
extensions:
- .jsx
- .js
- es6.js
- .sass
- .scss
- .worker
- .worker.js
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
- .eot
- .svg
- .ttf
- .woff
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: true
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/

test:
<<: *default
compile: true
# Compile test bundles to a separate directory
public_output_path: bundles-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true

我添加这个答案是为了帮助其他用户。

如果你不想在不重新加载浏览器的情况下更新js文件,请关闭hmr设置。

hmr: false

在RAILS中,webpacker.yml有不同的设置,其中之一是hmr,它是热模块替换,是一种Webpack功能,无需重新加载浏览器即可更新Javascript。热模块替换中的"模块"只是指您的每个Javascript源代码文件。为了实现这些更新,Webpack将HMR Runtime安装到您的输出捆绑包中。

有关HMR的更多详细信息-请查看此

最新更新