webpack命令不起作用 [英] webpack command not working

查看:95
本文介绍了webpack命令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Node Js和Webpack的新手.我试图用模块加载器开始一个项目.

I am new to Node Js and Webpack. I tried to start a project with module-loaders.

首先,我安装了nodeJs和NPM并创建了一个名为tutorial的新目录.我使用命令提示符cd进入此目录,然后运行以下命令npm init,然后使用以下命令通过npm安装了webpack:

Firstly, I installed nodeJs and NPM and created a new directory called tutorial. I used the command prompt to cd into this directory and then ran the following command npm init and then installed webpack via npm using the command below :

npm install -S webpack

第一个命令将webpack本地安装到"node-modules"目录下的项目中,我可以通过执行以下操作来运行我的项目:

The 1st command installed webpack locally into the project under the 'node-modules' directory and I can run my project by doing this:

nodejs node-modules/webpack/bin/webpack.js

此问题是我必须将webpack.config.js文件放置在要放置在项目根目录下的目录中.

The problem with this is that I have to place my webpack.config.js file inside of this directory which I want to place in my project root.

此问题的一种解决方案是使用以下命令在我的计算机上全局安装webpack:

One solution to this problem was to install webpack globally on my machine which I did using the command below :

npm install -g webpack

此已安装的Webpack,现在我有一个Webpack命令.但是,此命令似乎根本不起作用或什么也没做.当我尝试从项目的根目录Directroy运行此程序时,它根本不执行任何操作(请参见屏幕截图)

This installed Webpack and now I do have a Webpack command. However, this command does not seem to be working or doing anything at all. When I try to run this from my project's root directroy it does not do anything at all (See Screenshot)

请告诉我我在做什么错!!

Please tell me what I am doing wrong!!

推荐答案

webpack不仅在您的node-modules/webpack/bin/目录中,而且还链接在node_modules/.bin中.

webpack is not only in your node-modules/webpack/bin/ directory, it's also linked in node_modules/.bin.

您具有npm bin命令来获取npm将在其中安装可执行文件的文件夹.

You have the npm bin command to get the folder where npm will install executables.

您可以使用package.jsonscripts属性来使用此目录中的webpack,该目录将被导出.

You can use the scripts property of your package.json to use webpack from this directory which will be exported.

"scripts": {
  "scriptName": "webpack --config etc..."
}

例如:

"scripts": {
  "build": "webpack --config webpack.config.js"
}

然后可以使用以下命令运行它:

You can then run it with:

npm run build

甚至带有参数:

npm run build -- <args>

这使您可以将webpack.config.js放在项目的根文件夹中,而无需全局安装Webpack或在node_modules文件夹中进行webpack配置.

This allow you to have you webpack.config.js in the root folder of your project without having webpack globally installed or having your webpack configuration in the node_modules folder.

这篇关于webpack命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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