简体   繁体   English

如何使用全局安装的webpack?

[英]How to use globally installed webpack?

I want to use globally installed webpack, but executing the command webpack --mode development raises the message: 我想使用全局安装的webpack,但是执行命令webpack --mode development会显示以下消息:

webpack not installed

Install webpack to start bundling: 
  $ npm install --save-dev webpack

despite that I have both webpack and webpack-cli installed. 尽管我同时安装了webpack和webpack-cli。 Am I right, that webpack says webpack not installed itself? 我是对的,那个webpack说webpack not installed本身webpack not installed Isn't it strange? 奇怪吗?

What to do to successfully build projects globally install webpack and loaders, but using local webpack.config.js? 如何成功地在全球范围内构建项目,但要使用本地webpack.config.js来成功安装webpack和加载程序?

I was getting a similar error message, and it seems to be related to webpack not being found as a dependency of another package -- which by default won't include a globally installed package. 我收到类似的错误消息,这似乎与未将webpack作为另一个软件包的依赖项有关—默认情况下,该软件包将不包括全局安装的软件包。 As I understand it, the reason for an npm package to be installed globally is mainly so it can be accessed by the command line, and the general practice is to use local packages in all other situations, and even to install some packages both locally and globally. 据我了解,全局安装npm软件包的原因主要是可以通过命令行访问它,而通常的做法是在所有其他情况下使用本地软件包,甚至在本地和本地安装一些软件包。全球。

Adding my global node_modules directory to my $NODE_PATH environment variable fixed this error message for me. 将我的全局node_modules目录添加到$NODE_PATH环境变量后,为我修复了此错误消息。 However, this did not allow a globally installed babel-loader package to work with webpack, and I found it was much easier to just locally install the package I needed. 但是,这不允许全局安装的babel-loader软件包与webpack一起使用,我发现仅在本地安装所需的软件包要容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM