Rails 6服务器刚刚停止编译webpack。

问题描述 投票:2回答:1

我有一件非常奇怪的事情发生。

我在我的开发环境上做这个项目,当我用来启动Rails服务器的时候。

它将在第一次浏览器请求时编译webpack。

现在,突然间,这一切都没有发生,导致所有的javascript和样式都失败了,应用程序无法正常渲染。

Rails服务器控制台甚至没有显示[Webpacker]Compiling...一行。

如果我自己启动webpack-dev-server,它就会工作。但是不知道为什么,rails服务器自己就不做了,我把webpack_compile_output: false改成了true,但是rails服务器还是没有任何显示。我把webpacker.yml中的webpack_compile_output: false改为true,但是rails服务器仍然没有显示任何与Webpack有关的内容。

这真的很奇怪。我没有添加任何gems,也没有更新任何版本的node或webpack。我确实在我的机器上把Git从1.9版更新到2.24版,但仅此而已。

有什么好办法吗?

更新:(根据要求,这里是我的configwenpacker.yml的内容。

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  check_yarn_integrity: false
  webpack_compile_output: true

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: false

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

  extensions:
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
  check_yarn_integrity: false
   # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: false
    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 packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Extract and emit a css file
  extract_css: true

  # Cache manifest.json for performance
  cache_manifest: true

ruby-on-rails webpacker
1个回答
1
投票

我也遇到了这种情况。通常情况下 运行时 rails s 你会看到这样的东西。

Started GET "/react_test/hello" for ::1 at 2020-05-15 16:54:29 -0700

Processing by ReactTestController#hello as HTML
  Rendering react_test/hello.html.erb within layouts/application

[Webpacker] Everything's up-to-date. Nothing to do

如果你对一个 js (或 cssscss),这些都是你的webpack资源的一部分。

Processing by ReactTestController#hello as HTML
  Rendering react_test/hello.html.erb within layouts/application
[Webpacker] Compiling...
[Webpacker] Compiled all packs in /Users/foo/public/packs
[Webpacker] Hash: 1ea802b336ed3c771c61
Version: webpack 4.43.0
Time: 4844ms

... truncated for brevity (a list of assets, size, etc)

在某一时刻,所有这些都会停止--你将 "不得不 "执行 两者 rails s ./bin/webpack-dev-server 手动. 到目前为止,我注意到的是,当你运行了 webpack-dev-server - 例如,在更新 config/webpacker.yml - 它确实在该文件本身的注释中说过。

# Note: You must restart bin/webpack-dev-server for changes to take effect


试试这个 变通办法:

  1. 停止 Rails serverwebpack-dev-server
  2. 暂时改变你的 /app/javascript/packs/application.js 档案
    • 例如,注释掉一个导入。//import 'bootstrap'
  3. 重新开始 rails s (只是, webpack-dev-server)
  4. 这将会出错--因为它缺少了被注释出来的内容(在这个例子中 bootstrap
  5. 取消对临时变更的批注
  6. 重新加载页面--希望它应该是好的(Webpack编译等)。

我想(猜测)是一些缓存同步的问题,通过对以下内容做一些修改来 "修复(重置?) application.js

Hth...

© www.soinside.com 2019 - 2024. All rights reserved.