为什么包装脚本的行为与相同的终端命令有所不同
在我的npm
项目中,在我的package.json
文件中,我有以下代码行:
"scripts": {
"build": "webpack"
},
在终端中,如果我运行npm webpack
,我收到错误消息:
Unknown command: "webpack"
但是,如果我运行npm run build
,我从webpack中得到一个提示,说我需要webpack-cli ...因此,显然可以识别命令。
我对这两个命令的不同行为感到困惑。在这种情况下,运行npm run build
与我的终端中的npm webpack
相同吗?为什么一个命令失败并成功?当我运行npm run build
时,实际发生了什么?
In my npm
project, in my package.json
file, I have the following lines of code:
"scripts": {
"build": "webpack"
},
While in my terminal, if I run npm webpack
, I get the error message:
Unknown command: "webpack"
But if I run npm run build
, I get a prompt from webpack saying I need webpack-cli... so the command is obviously recognized.
I'm confused about the different behavior of these two commands. In this case, isn't running npm run build
identical to running npm webpack
in my terminal? Why does one command fail and one succeed? What is actually happening when I run npm run build
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我们查看 documentation>,
也许这就是命令行识别的原因
webpack
。If we look at the documentation,
Maybe this is the reason
webpack
is not recognized by the command line.