【问题标题】:Webpacker not compiling liveWebpacker 没有实时编译
【发布时间】:2019-07-29 22:05:36
【问题描述】:

我正在运行我的 Rails 应用程序并安装了 Webpacker。我将 webpack-dev-server 作为 Docker 容器运行,但它似乎没有响应我的文件中的更改并重新编译。

谁能检查我的配置,看看他们是否能发现任何错误?

docker-compose.yml:

version: '3.7'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 3000:3000
      - 35729:35729
      - 5000:5000
    env_file:
      - '.env'
    volumes:
      - .:/app
      - type: tmpfs
        target: /app/tmp/pids/
    depends_on:
      - database
      - elasticsearch
      - webpacker

  database:
    image: postgres:9.6-alpine
    env_file:
      - '.env'
    volumes:
      - pg-data:/var/lib/postgresql/data

  webpacker:
    build: .
    command: ./bin/webpack-dev-server
    env_file:
      - '.env'
    volumes:
      - .:/app
    ports:
      - 3035:3035

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.1
    env_file:
      - '.env'
    volumes:
      - es-data:/usr/share/elasticsearch/data
    ports:
      - 9200:9200

volumes:
  pg-data:
  es-data:

config/webpacker.yml:

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

default: &default
  source_path: app/webpacker
  source_entry_path: packs
  public_output_path: public/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:
    - .js
    - .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: webpacker
    port: 3035
    public: webpacker: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

config/webpack/loaders/sass.js:

{
  loader: 'postcss-loader',
  options: {
    sourceMap: true,
    plugins: (loader) => [
      require('postcss-cssnext')({
        features: {
          customProperties: {
            warnings: false
          }
        }
      })
    ]
  }
}

我的文件是这样的结构:

我希望你能帮助我,因为这正在阻止我开发这个应用程序。

谢谢

【问题讨论】:

    标签: ruby-on-rails webpack assets webpack-dev-server webpacker


    【解决方案1】:

    默认情况下,webpack 开发服务器的代码重新加载依赖于 fsevents,这些事件不在 docker 内部交付。

    对于在 docker 内运行,您可以切换到轮询更改,在 webpacker.yml:

    dev_server:
      ...
      watch_options:
        poll: 1000
        aggregate_timeout: 100
    

    也尝试安装最新版本的 docker,有报道说 fsevents 正在其中工作。

    【讨论】:

    • 这似乎运作良好。这有点慢,但我很高兴它有效。谢谢。知道为什么默认情况下未设置这些选项吗?我怎么知道我需要它们?
    • @rctneil 这些不是默认值,因为事件监视比它们启用的轮询(开发服务器每 1000 毫秒检查一次是否有任何更改而不是由操作系统通知)更有效,这应该是仅在后者不工作时使用
    • 好的,那么我如何让事件工作而不是轮询?
    • Evented 由于 Docker 而无法工作(这就是为什么建议更新它,但可能会发生这种情况并没有帮助,你必须坚持轮询)你也可以尝试降低轮询间隔,但要注意 cpu 负载,延迟小的轮询会产生更高的系统负载
    猜你喜欢
    • 2019-10-02
    • 2017-12-16
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多