0

使用 Docker 和 Docker Compose,升级到 webpacker 3.3.0 后,我无法启动并运行 webpacker 服务。之后的输出docker-compose up是:

webpack dev_server configuration not found in /app/config/webpacker.yml.
Please run bundle exec rails webpacker:install to install Webpacker

我已经运行webpacker:install了 - 它进行了更改,但输出是相同的。我还运行rails new test --webpacker并比较了配置文件。到目前为止,工作生成的应用程序和我自己的应用程序之间唯一显着的区别是 Node 版本。在典型 RVM 环境中的本地计算机上,节点版本为v9.4.0,在 docker 映像中为v8.9.3. 两种环境中的纱线都是1.3.2.

我的 config/webpacker.yml 和生成的几乎一模一样。唯一的区别是添加了一些扩展:

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

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker

  # 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

  extensions:
    - .coffee
    - .erb
    - .js
    - .jsx
    - .ts
    - .vue
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # 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: 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 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

  # Cache manifest.json for performance
  cache_manifest: true

配置/webpack/environment.js:

const { environment } = require('@rails/webpacker')

module.exports = environment

配置/webpack/development.js:

const environment = require('./environment')

module.exports = environment.toWebpackConfig()

关于为什么找不到 dev_server 配置的任何想法?我不相信节点版本是原因。

4

1 回答 1

0

正如他们的更新日志中提到的,Webpacker 3.1.0 和 3.1.1 已损坏,应该避免使用。

我将问题缩小到 webpacker 中的这个块:

def load_config
  @config_file = File.join(@app_path, "config/webpacker.yml")
  dev_server = YAML.load_file(@config_file)[ENV["NODE_ENV"]]["dev_server"]

  @hostname          = dev_server["host"]
  @port              = dev_server["port"]
  @pretty            = dev_server.fetch("pretty", true)

rescue Errno::ENOENT, NoMethodError
  $stdout.puts "webpack dev_server configuration not found in #{@config_file}."
  $stdout.puts "Please run bundle exec rails webpacker:install to install Webpacker"
  exit!
end

我不确定为什么 gem 中没有 NODE_ENV 的后备,但是此代码依赖于 NODE_ENV 被填充并匹配在 config/webpacker.yml 中具有您的 dev_server 键的键。他们依赖于将 NODE_ENV 设置为 RAILS_ENV 的 binstub。您可以使用bundle exec rails webpacker:binstubs.

这是 bin/webpack-dev-server 的示例:

#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
  Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

require "webpacker"
require "webpacker/dev_server_runner"
Webpacker::DevServerRunner.run(ARGV)

我生成了几次 binstubs,但我相信我遇到了阻止修复的 docker 缓存问题。docker volume -rm webpacker可能是什么解决了这个问题 - 不确定。

于 2018-03-07T20:55:21.623 回答