ruby-on-rails - Webpacker 未实时编译

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

我运行了 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:

配置/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

配置/webpack/loaders/sass.js:
{
  loader: 'postcss-loader',
  options: {
    sourceMap: true,
    plugins: (loader) => [
      require('postcss-cssnext')({
        features: {
          customProperties: {
            warnings: false
          }
        }
      })
    ]
  }
}

我的文件采用以下结构:
enter image description here

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

谢谢

最佳答案

对于默认情况下重新加载代码,webpack 开发服务器依赖于 fsevents,它们不在 docker 内部交付。

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

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

还尝试安装最新版本的 docker,有报告称 fsevents 正在其中运行。

关于ruby-on-rails - Webpacker 未实时编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55053633/

相关文章:

ruby-on-rails - Activerecord按ENUM分组

javascript - Webpack 的 bootrstrap-sass 错误 : Bootstrap´s JavaScript requires jQuery

Android:如何从 Assets 文件创建 File 对象?

java - SQLite异常: No such table even if there is table

javascript - 搜索 UI 自动完成输入

ruby-on-rails - 获取自定义 attr_accessor 的未定义方法 `validates_presence_of'

ruby-on-rails - 安装 Ruby Gems 时遇到问题?

webpack - 如何从子目录提供 Vue.js webpack 项目

javascript - Angular jquery 插件 - 插件中未定义 jQuery

android - 多设备混合应用程序 - 支持 Android 上的 xxhdpi 和 xxxhdpi 密度