在项目中运行 webpack [英] Running webpack within project
问题描述
我是否必须全局安装 webpack 才能发出 webpack 命令?
Do I have to install webpack globally for me to issue webpack commands?
我使用 npm install webpack --save-dev
在我的项目文件夹中安装了 webpack,并将其添加到开发依赖项中.我在我的项目文件夹中,当我运行 webpack 命令时,出现以下错误:
I installed webpack inside my project folder using npm install webpack --save-dev
and added it to dev dependencies. I'm inside my project folder and when I run a webpack command, I get the following error:
'webpack' 不被识别为内部或外部命令,可运行的程序或批处理文件.
'webpack' is not recognized as an internal or external command, operable program or batch file.
顺便说一句,我使用的是 Windows 10.
BTW, I'm on Windows 10.
推荐答案
将命令添加为 npm 脚本.在你的 package.json 中.
Add the command as a npm script. In your package.json.
{
"name": "app",
"version": "0.0.1",
"scripts": {
"compile": "webpack --config webpack.config.js"
}
}
然后运行
npm run compile
npm 脚本查找在 ./node_modules/.bin 文件夹中创建的可执行文件.当 webpack 安装在本地时,它会在同一个文件夹中创建一个二进制文件.
npm scripts looks for executable created in ./node_modules/.bin folder. When the webpack is locally installed it creates a binary in the same folder.
这篇关于在项目中运行 webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!