我有一件非常奇怪的事情发生。
我在我的开发环境上做这个项目,当我用来启动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
我也遇到了这种情况。通常情况下 运行时 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
(或 css
scss
),这些都是你的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
试试这个 变通办法:
Rails server
和 webpack-dev-server
/app/javascript/packs/application.js
档案//import 'bootstrap'
rails s
(只是, 不 webpack-dev-server
)bootstrap
我想(猜测)是一些缓存同步的问题,通过对以下内容做一些修改来 "修复(重置?) application.js
Hth...