我在Rails 5.2.2应用程序中有gem 'webpacker', '~> 3.5'
,但是当在.bin/webpack-dev-server
的单独终端中运行rails s
时,我看不到我的/app/CSS/
文件夹中的任何样式,只是localhost:3000
上的纯文本。 localhost:3035
只是展示了cannot GET/
。我在应用程序或控制台中没有收到任何错误。 $.bin/webpack-dev-server
是正确的终端命令吗?
application.html.erb
<%= javascript_pack_tag 'application' %>
<%= stylesheet_pack_tag 'application', media: 'all' %>
的JavaScript /包/的application.js
import '../css/simple-grid.css';
import '../css/application.css'
webpacker.yml
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:
- .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
port: 3035
public: localhost:3035
hmr: true
# 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
的package.json
{
"name": "GD",
"private": true,
"dependencies": {
"@rails/webpacker": "3.5",
"autoprefixer": "^9.4.5",
"axios": "^0.18.0",
"babel-preset-react": "^6.24.1",
"prop-types": "^15.6.2",
"react": "^16.7.0",
"react-autosize-textarea": "^6.0.0",
"react-dom": "^16.7.0",
"react-responsive-navbar": "^1.0.11",
"react-select": "^2.3.0",
"webpack-cli": "^3.2.3"
},
"devDependencies": {
"webpack-dev-server": "2.11.2"
}
}
我在控制台中没有错误,它告诉我webpack Compiled Successfully
:
^CSimons-MBP-2:GD Simon$ ./bin/webpack-dev-server
Project is running at http://localhost:3035/
webpack output is served from /packs/
Content not from webpack is served from /Users/Simon/Sites/GD/public/packs
404s will fallback to /index.html
Hash: 1b5e7c9ec1725de169c0
Version: webpack 3.12.0
Time: 2444ms
Asset Size Chunks Chunk Names
application-1b5e7c9ec1725de169c0.js 436 kB 0 [emitted] [big] application
application-1b5e7c9ec1725de169c0.js.map 495 kB 0 [emitted] application
manifest.json 142 bytes [emitted]
[0] multi (webpack)-dev-server/client?http://localhost:3035 webpack/hot/dev-server ./app/javascript/packs/application.js 52 bytes {0} [built]
[./app/javascript/css/application.css] ./app/javascript/css/application.css 1.34 kB {0} [built]
[./app/javascript/css/simple-grid.css] ./app/javascript/css/simple-grid.css 1.34 kB {0} [built]
[./app/javascript/packs/application.js] ./app/javascript/packs/application.js 538 bytes {0} [built]
[./node_modules/loglevel/lib/loglevel.js] ./node_modules/loglevel/lib/loglevel.js 7.86 kB {0} [built]
[./node_modules/strip-ansi/index.js] ./node_modules/strip-ansi/index.js 161 bytes {0} [built]
[./node_modules/url/url.js] ./node_modules/url/url.js 23.3 kB {0} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:3035] (webpack)-dev-server/client?http://localhost:3035 7.93 kB {0} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.67 kB {0} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.08 kB {0} [built]
[./node_modules/webpack/hot ^\.\/log$] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {0} [built]
[./node_modules/webpack/hot/dev-server.js] (webpack)/hot/dev-server.js 1.61 kB {0} [built]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 77 bytes {0} [built]
[./node_modules/webpack/hot/log-apply-result.js] (webpack)/hot/log-apply-result.js 1.31 kB {0} [built]
[./node_modules/webpack/hot/log.js] (webpack)/hot/log.js 1.04 kB {0} [built]
+ 20 hidden modules
webpack: Compiled successfully.
某处显然出现了问题,但没有任何错误信息,我无法发现问题所在。