[英]Ruby on Rails 6 + Docker = Webpacker::Manifest::MissingEntryError?
[英]HRM is not working on Ruby on Rails with Webpacker and Docker
我在 docker 中有一個帶有 Ruby on Rails 6、Webpacker 和 react-rails 的容器,當我重新加載頁面時,它的編譯延遲超過 20 秒,所以我想向我的項目添加熱重新加載,但它只是不起作用。 webpack-dev-server 運行良好,但頁面沒有更新更改。
我正在使用 foreman 運行 bin/webpack-dev-server 和 rails server,我正在使用 react-refresh-webpack-plugin 來刷新 react。 當我更改代碼時,即使我重新加載頁面,頁面也不會收到更改。
docker-compose.yml
version: '3.3'
services:
mysql:
image: mysql:latest
restart: always
command: mysqld --default-authentication-plugin=mysql_native_password
ports:
- 3307:3306
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: development
ruby:
build: .
image: alexisnoe27/ubuntu_rails:master
command: bash -c '
cd rails_app &&
bundle update &&
yarn &&
rm -f tmp/pids/server.pid &&
bundle exec foreman start -f Procfile.dev'
environment:
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_PORT: 3306
MYSQL_HOST: mysql
MYSQL_DATABASE: development
RAILS_ENV: development
NODE_ENV: development
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
expose:
- 3000
- 3035
ports:
- 3000:3000
- 3035:3035
depends_on:
- mysql
links:
- mysql
volumes:
- ./:/rails_app
tty: true
stdin_open: true
開發文件
webpack: bin/webpack-dev-server
web: bundle exec rails s -b 0.0.0.0 -p 3000
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_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
additional_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:
- .jsx
- .mjs
- .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: localhost
hmr: true
port: 3035
public: localhost:3035
# 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
pretty: 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
開發.js
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const environment = require('./environment')
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER;
if (isWebpackDevServer) {
console.log('true')
environment.plugins.append(
'ReactRefreshWebpackPlugin',
new ReactRefreshWebpackPlugin({
overlay: {
sockPort: 3035
}
})
);
}
module.exports = environment.toWebpackConfig()
控制台輸出
我可以解決它,webpack 沒有監視我的文件,我在 webpacker.yml 的 watch_options 中添加了 aggregateTimeout: 300 和 poll: 500,並且它起作用了。
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
additional_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:
- .jsx
- .mjs
- .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: localhost
hmr: true
port: 3035
public: localhost:3035
# 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
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
aggregateTimeout: 300
poll: 500
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.