Webpack 运行 构建并观察错误
Webpack run build & watch ERROR
我在媒体上阅读 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 配置文件。
应该是这样的
"build": "webpack --progress -p --config /node_modules/.bin/webpack.config.js"
我在媒体上阅读 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 配置文件。
应该是这样的
"build": "webpack --progress -p --config /node_modules/.bin/webpack.config.js"