简体   繁体   English

我如何安装 gulp 4

[英]How do I install gulp 4

I've been using gulp-watch.我一直在使用 gulp-watch。 The current version of gulp-watch relies on the call gulp.parrallel.当前版本的 gulp-watch 依赖于调用 gulp.parrallel。 This call is only available from gulp 4.此调用仅适用于 gulp 4。

However gulp 4 is not available via the npm repo.但是 gulp 4 不能通过 npm repo 获得。 npm info gulp dist-tags returns: { latest: '3.9.0' } . npm info gulp dist-tags返回: { latest: '3.9.0' }

I can see that there is a 4.0 branch within the git repo.我可以看到 git repo 中有一个 4.0 分支。 But attempting to install it with variations on this command fails: npm install https://github.com/gulpjs/gulp#v4.0.0 .但是尝试使用此命令的变体安装它失败: npm install https://github.com/gulpjs/gulp#v4.0.0

npm install gulpjs/gulp.git#4.0 --save-dev

Gulp has removed the 4.0 branch from their GitHub repository, so the previous way of installing using npm install gulpjs/gulp.git#4.0 --save-dev no longer works. Gulp已经从他们的GitHub存储库中删除了4.0分支,因此使用npm install gulpjs/gulp.git#4.0 --save-dev的先前安装方式不再有效。

They state in their README that the correct way to install gulp 4.0 is to run the command: 他们在自述文件中声明安装gulp 4.0的正确方法是运行命令:

npm install gulp@next

# Uninstall previous Gulp installation and related packages, if any
$ npm rm gulp -g
$ npm rm gulp-cli -g
$ cd [your-project-dir/]
$ npm rm gulp --save-dev
$ npm rm gulp --save
$ npm rm gulp --save-optional
$ npm cache clean # for npm < v5

# Install the latest Gulp CLI tools globally
$ npm install gulpjs/gulp-cli -g

# Install Gulp 4 into your project as dev dependency
$ npm install gulp --save-dev

# Check the versions installed. Make sure your versions are not lower than shown.
$ gulp -v
---
[10:48:35] CLI version 2.0.1
[10:48:35] Local version 4.0.0

Detail info is on this blog page: https://demisx.github.io/gulp4/2015/01/15/install-gulp4.html 详细信息在此博客页面上: https//demisx.github.io/gulp4/2015/01/15/install-gulp4.html

Run the following to check the version of gulp cli that is installed on your machine. 运行以下命令以检查计算机上安装的gulp cli的版本。

gulp -v

If you are not running version 4, do the following to install gulp globally on your machine. 如果您未运行版本4,请执行以下操作在您的计算机上全局安装gulp。

npm uninstall -g gulp
npm install -g "gulpjs/gulp#4.0"

Now install gulp 4 locally 现在在本地安装gulp 4

npm uninstall gulp --save-dev
npm install "gulpjs/gulp#4.0" --save-dev

2018年11月»npm审计说运行: npm install --save-dev gulp@4.0.0

to install gulp-4, CLI version has to be 1.2.2 which will support gulp 4.0 要安装gulp-4, CLI版本必须是1.2.2才能支持gulp 4.0

to install gulp-cli 1.2.2 run sudo npm install gulp-cli@1.2.2 -g sudo npm install gulp-cli@1.2.2 -g -cli 1.2.2运行sudo npm install gulp-cli@1.2.2 -g

and to install gulp 4.0 run npm install 'gulpjs/gulp.git#4.0' --save-dev 并安装npm install 'gulpjs/gulp.git#4.0' --save-dev 4.0运行npm install 'gulpjs/gulp.git#4.0' --save-dev

when you run gulp -v command 当你运行gulp -v命令

you should get 你应该得到

[11:38:36] CLI version 1.2.2 [11:38:36] CLI版本1.2.2

[11:38:36] Local version 4.0.0-alpha.2 [11:38:36]本地版本4.0.0-alpha.2

similar issue on GitHub GitHub上的类似问题

My installation was a bit different. 我的安装有点不同。

Running 运行

npm install 'gulpjs/gulp.git#4.0' --save-dev

Or 要么

npm install 'gulpjs/gulp#4.0' --save-dev

Gave me an error: 给我一个错误:

npm ERR! 错误的ERR! code EINVALIDTAGNAME npm ERR! 代码EINVALIDTAGNAME npm ERR! Invalid tag name "gulp#4.0": Tags may not have any characters that encodeURIComponent encodes. 无效的标记名称“gulp#4.0”:标记可能没有任何encodeURIComponent编码的字符。

NB I was only having problems installing my local gulp-4 so I took a look at my last package.json installation and saw this: 注意我只是在安装我的本地gulp-4时遇到问题,所以我看了我上一次的package.json安装并看到了这个:

"gulp": "github:gulpjs/gulp#4.0",

So my move was to install local gulp with 所以我的举措是安装本地gulp

npm install "github:gulpjs/gulp#4.0" --save-dev

and that worked, installing local gulp 4 successfully. 这工作,成功安装本地gulp 4。

[15:45:55] CLI version 1.4.0
[15:45:55] Local version 4.0.0-alpha.2

截至2018年12月28日,以下命令在本地安装版本4时应该可以正常工作。

npm i -D gulp

I wrote a batch file that does the job based on what @demisx answered. 我写了一个批处理文件 ,根据@demisx的回答完成了这项工作。

The problem I had was a missing npm config parameter 'prefix', so my global directory was the node binary directory. 我遇到的问题是缺少npm配置参数'prefix',所以我的全局目录是节点二进制目录。 I am pretty sure this wasn't always the case, but I could (re-)set it running this script from the project root directory: 我很确定情况并非总是这样,但我可以(重新)设置它从项目根目录运行此脚本:

@ECHO OFF
echo configuring npm
set USERNAME=<enter username>
set USERPROFILE=C:\Users\%USERNAME%
set APPDATA=%USERPROFILE%\AppData\Roaming
call npm config set prefix %APPDATA%\npm

SET DIR_PROJECT="D:/stuff/plugins/wallpaper_engine/raintime-dev"

echo Uninstall previous Gulp installation and related packages, if any
call npm rm gulp -g
call npm rm gulp-cli -g

echo cd %DIR_PROJECT%
cd /D %DIR_PROJECT%

call npm rm gulp --save-dev
call npm rm gulp --save
call npm rm gulp --save-optional
call npm cache clean

echo Install the latest Gulp CLI tools globally
call npm install gulpjs/gulp-cli -g

echo Install Gulp 4 into your project from 4.0 GitHub branch as dev dependency
rem call npm install gulpjs/gulp#4.0 --save-dev
call npm install gulpjs/gulp --save-dev

echo Check the versions installed.

call gulp -v

pause

The script finally showed this: 剧本终于显示了这个:

[14:59:48] CLI version 2.0.1
[14:59:48] Local version 4.0.0

Hope it helps! 希望能帮助到你!

我通过运行解决了这个问题:

which gulp
rm -rf /usr/local/bin/gulp
npm i -g gulp

Windows still wouldn't upgrade. Windows 仍然不会升级。 The below commands from another Linux post seemed to clear it out, and afterwards success.来自另一个 Linux 帖子的以下命令似乎清除了它,然后成功了。

Can't seem to upgrade gulp to 4.0 from 3.9似乎无法将 gulp 从 3.9 升级到 4.0

Uninstall previous Gulp installation and related packages, if any:卸载以前的 Gulp 安装和相关包,如果有的话:

$ npm rm gulp -g
$ npm rm gulp-cli -g
$ cd [your-project-dir/]
$ npm rm gulp --save-dev
$ npm rm gulp --save
$ npm rm gulp --save-optional

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

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