【问题标题】:Webpacker slow and duplicate files in public/assetsWebpacker 在公共/资产中缓慢和重复文件
【发布时间】:2020-02-29 20:53:20
【问题描述】:

使用 Rails / Webpacker 编译资产。

Webpacker 开始变得非常慢(编译时间为 3 分钟)。我注意到public/assets 文件夹中充满了指纹资产,例如..

application-1e69eb85a81f4a963fde.js application-828cf61e1e6dc295ffee.js application-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

【问题讨论】:

  • 可以分享一下 webpacker.yml 文件吗?
  • 刚刚更新的问题
  • 你能把hmr设为false然后试试吗?
  • 是的,有效。谢谢

标签: ruby-on-rails ruby-on-rails-6 webpacker


【解决方案1】:

我正在添加这个答案,以便它可以帮助其他用户。

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

hmr: false

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

关于HMR的更多细节-CHECK THIS

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    相关资源
    最近更新 更多