在Ruby on Rails项目中使用Webpack时遇到一些麻烦。我正在关注WebCrunch(https://web-crunch.com/lets-build-with-ruby-on-rails-project-management-app/)上的教程系列。当我尝试运行webpack-dev-server时,出现以下错误:
找不到配置文件,也没有通过CLI选项配置的条目。 使用CLI时,您至少需要提供两个参数:entry 和输出。配置文件在以下位置可以命名为“ webpack.config.js” 当前目录。使用--help显示CLI选项。
因此,我改为运行webpack-dev-server --config config / webpacker.yml并收到此错误:
找到配置文件,但未配置任何条目。使用--help 显示CLI选项。
随附的是我的webpacker.yml文件以及package.json。我还将附上项目目录的屏幕快照。
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_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:
- .coffee
- .erb
- .js
- .jsx
- .ts
- .vue
- .sass
- .scss
- .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: 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
package.json
{
"name": "Groupie",
"private": true,
"dependencies": {
"@rails/webpacker": "^3.2.0",
"coffeescript": "1.12.7",
"require-yaml": "0.0.1",
"rvm": "^0.3.2",
"vue": "^2.6.10",
"vue-loader": "^15.7.0",
"vue-template-compiler": "^2.6.10",
"webpack": "^2.2.0",
"webpack-dev-server": "^2.10.1"
},
"devDependencies": {}
}
更新:
运行./bin/webpack-dev-server后,出现以下错误:
无效的配置对象。 Webpack已使用初始化 与API模式不匹配的配置对象。 -configuration.module具有未知属性'strictExportPresence'。这些属性有效:object { exprContextCritical?,exprContextRecursive?,exprContextRegExp ?、 exprContextRequest ?、装载程序?,noParse ?、规则?, unknownContextCritical?,unknownContextRecursive ?、 unknownContextRegExp?,unknownContextRequest?,unsafeCache ?、 wrappedContextCritical?,wrappedContextRecursive ?、 wrapContextRegExp? }影响普通模块的选项 (
NormalModuleFactory
。
答案 0 :(得分:0)
您是否已正确安装Webpack?
bundle exec rails webpacker:install
要运行开发服务器,请使用以下命令:
./bin/webpack-dev-server