运行“ webpack”而不是“ node_modules / .bin / webpack” [英] Running "webpack" instead of "node_modules/.bin/webpack"

查看:368
本文介绍了运行“ webpack”而不是“ node_modules / .bin / webpack”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在运行 node_modules / .bin / webpack ,但是我知道可以配置路径,这样您只需键入 webpack 。不过,我找不到方法。 :/

I'm using to run "node_modules/.bin/webpack", but I know it's possible to configure the path so that you only have to type "webpack". I can't find how, though. :/

推荐答案

如果安装软件包全局。对于使用命令 npm install -g webpack 的Webpack,在这种情况下, npm 会将Webpack安装在一组中 npm root -g 找到的位置。

That would happen if you install a package globally. For webpack that would be with the command npm install -g webpack .npm in that case would install Webpack in a set location you can find with npm root -g.

如果该位置在您的中$ PATH ,则可以直接在命令行中使用 webpack 。不要那样做!对于不同的项目,您可能需要不同版本的webpack。相反,如果您使用的是NPM,请在project / package.json所在的目录中使用 npx webpack npx webpack ./ node_modules / .bin / webpack的快捷方式。 npx 已包含在 npm 中。在此处了解更多信息。

If that location is in your $PATH, you can use webpack directly on your command line. Do not do that! You would proabably need different versions of webpack for different projects. Instead, if you are using NPM, use npx webpack in directory where your project / package.json is. npx webpack is a shortcut to ./node_modules/.bin/webpack. npx is already included with npm. Read more here.

或者另一个选择是将其放入您的package.json 脚本属性,例如:

Or another option is to put it in your package.json scripts property like:

{
    "scripts": {
        "build": "webpack"
    }
}

然后,您可以使用命令 npm run build 。如果存在,NPM也会优先使用本地版本而不是全局版本。

Then you can run the local webpack with the command npm run build.NPM will then also prefer the local version over a global version if existent.

有关更多信息,请阅读此文章: http://ericlathrop.com/2017/05/the-problem-with-npm-install-global/

For more information, read this article: http://ericlathrop.com/2017/05/the-problem-with-npm-install-global/

这篇关于运行“ webpack”而不是“ node_modules / .bin / webpack”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆