5

我正在尝试测试自定义 Webpack 配置。我已经读过,而不是打字node ./node_modules/webpack/bin/webpack.js,我可以使用npx webpack. 但我似乎无法让它工作。

user@comp:~/raw> npx webpack
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

当我切换到 running 时npx webpack-cli,我得到一个不同的错误:

user@comp:~/> npx webpack-cli
npx: installed 489 in 19.186s
Cannot find module 'webpack'
4

4 回答 4

1

你可以全局安装 webpack 和 webpack-cli 包,这样你就不需要使用node ./path/to/webpack

  $ npm install webpack webpack-cli -g

这将在您的机器上全局安装 webpack。然后在您的项目文件夹中运行

  $ webpack
于 2018-04-01T07:56:18.200 回答
1
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

基本上就是这样。安装 webpack-cli 后,只需使用

npx webpack
于 2018-04-01T07:30:58.333 回答
0

我遵循其他答案中的建议并使用npm install webpack webpack-cli -g.

当我跑的时候npx webpack,我得到了

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.
Use --help to display the CLI options.

就在那时我意识到我不在项目文件夹中......

于 2018-04-03T16:42:23.163 回答
-1

我尝试webpack-cli再次安装,它工作

于 2021-06-26T03:57:40.150 回答