请别人向我解释一下。 我想使用命令npm run build来调用webpack。所以我修改了文件package.json中的脚本。但它没有用。我正在使用linux
这是我的package.json文件
{
"name": "learn-webpack",
"version": "1.0.0",
"description": "Learn Webpack",
"main": "index.js",
"scripts": {
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"css-loader": "^0.28.11",
"style-loader": "^0.20.3",
"webpack": "^4.2.0"
}
}
这是错误,它已经安装了cli但它会继续发送此消息
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! learn-webpack@1.0.0 build: `webpack`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the learn-webpack@1.0.0 build script.
npm ERR! This is probably not a problem with npm.
There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/huong/.npm/_logs/2018-03-27T14_09_22_103Z-debug.log
答案 0 :(得分:3)
按照说明
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
跑步:
npm install webpack-cli -D -g
-g
为了更好的衡量标准,然后尝试再次运行构建,它应该可以工作:)
答案 1 :(得分:3)
您没有将webpack-cli安装到您的devDependencies
中npm install webpack-cli -D
其实应该解决你的问题
也许您在全球范围内安装了webpack-cli,但它不在您的devDependencies中
答案 2 :(得分:3)
如果您直接调用函数
"scripts": {
"build": "webpack"
},
从$ PATH中搜索Webpack作为命令。
使用npm install webpack-cli -D
不是全局安装在$ PATH下,而是在./node_modules
下本地安装。
因此,您有两个选择:
npm -g i webpack-cli
node_modules/<path to webpack>
答案 3 :(得分:1)
如果您将webpack安装到项目中而不是全局,请尝试以下方法:
"build": "./node_modules/webpack/bin/webpack"