Running “webpack” instead of “node_modules/.bin/webpack”

匆匆过客 提交于 2019-12-11 01:19:39

问题


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. :/


回答1:


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.

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.

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

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

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.

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



来源:https://stackoverflow.com/questions/52566181/running-webpack-instead-of-node-modules-bin-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!