[翻译]  How do you run gulp if gulp is installed(node_modules) in different folder than gulpfile.js

[CHINESE]  如果在gulpfile.js之外的不同文件夹中安装gulp(node_modules),你如何运行gulp


I have gulpfile.js in one directory and node_modules in another. When I run gulp, i get the error - 'Local gulp not found in '..(the directory).. Try running: npm install gulp'

我在一个目录中有gulpfile.js,在另一个目录中有node_modules。当我运行gulp时,我收到错误 - '找不到本地gulp .. ..(目录)..尝试运行:npm install gulp'

The thing is - I cannot install gulp in the directory of gulpfile.js and so I need a way to tell the gulp to refere to the other directory i have gulp installed in.

问题是 - 我无法在gulpfile.js的目录中安装gulp,因此我需要一种方法告诉gulp参考我安装了gulp的其他目录。

4 个解决方案

#1


19  

You don't need to install gulp globally if you don't want to. What you can do is run your gulp executable (from your node_modules) and then pass in the location of your gulpfile using the --gulpfile parameter. Also, if you want to control where your gulp is running, make use of the --cwd parameter.

如果您不想,则无需全局安装gulp。你可以做的是运行你的gulp可执行文件(来自你的node_modules),然后使用--gulpfile参数传入你的gulpfile的位置。此外,如果要控制gulp的运行位置,请使用--cwd参数。

Here's an example:

这是一个例子:

 <NODE_MODULES DIR>/gulp/bin/gulp.js --gulpfile <GULP FILE> --cwd <SOME DIR>

#2


2  

There is no need to install gulp globally. First install gulp (ideally on dev dependencies)

全局无需安装gulp。首先安装gulp(理想情况下是dev依赖项)

npm install gulp --save-dev

npm install gulp --save-dev

Then in the package.json add the line you want to run

然后在package.json中添加要运行的行

"scripts" : { "gulp" : "gulp"} }

“脚本”:{“gulp”:“gulp”}}

Finally in the command line use

最后在命令行中使用

npm run gulp

npm run gulp

npm will use the binary from the node modules without any need to install it globally or to write down the whole path

npm将使用节点模块中的二进制文件而无需全局安装或写下整个路径

#3


1  

You need to install gulp globally:

您需要全局安装gulp:

npm install -g gulp

npm install -g gulp

This will allow you to run gulp from the command line in any directory.

这将允许您从任何目录中的命令行运行gulp。

#4


0  

Put the node_modules folder in parent directory always, then make project directory as child/grandchild folder.

将node_modules文件夹始终放在父目录中,然后将项目目录作为子/孙子文件夹。

Don't put the node_modules folder in any child directory

不要将node_modules文件夹放在任何子目录中

Folder structure will be like:

文件夹结构如下:

parent

└──node_modules

└──node_modules

└─project_1

└─project_1

└─project_2

└─project_2

In any child/grand child directory gulp will work

在任何子/大孩子目录gulp将工作


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号