【发布时间】:2018-05-05 14:57:19
【问题描述】:
我在 medium 上阅读了story,试图学习如何使用 npm 和 webpack 以及现代 JavaScript。在我安装 webpack 之前,一切都很棒。
我尝试运行此命令npm run build 和npm run watch 这些脚本存在于package.json 文件中,为
{
"name": "ebdae",
"version": "1.0.0",
"description": "nodescription",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --progress -p",
"watch": "webpack --progress --watch"
},
"repository": {
"type": "git",
"url": "ebdae"
},
"author": "elhakim",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"webpack": "^3.8.1"
},
"dependencies": {}
}
但是这会在命令行No configuration file found and no output filename configured via CLI option.
A configuration file could be named 'webpack.config.js' in the current directory.显示这个错误
但配置文件通常存在于.bin文件夹中,并且包含以下代码:
module.exports = {
entry: '../../assets/js/index.js',
output: {
filename: '../../assets/js/bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
}
]
}
};
树结构如下:
| .git
| assets
| js
| index.js
| bundle.js
| node_modules
| .bin
| ...
| webpack.config.js
| package-lock.json
| package.json
【问题讨论】:
-
您好,您没有在脚本中提供任何
webpack configuration文件。应该是这样的"build": "webpack --progress -p --config /node_modules/.bin/webpack.config.js" -
谢谢 @pravesh-khatri,我更改了输入和输出路径以使其正常工作,我将
../../替换为./。同样,--display-error-details救了我的培根。 非常感谢。
标签: npm webpack build command watch