如何在CentOS 7/Fedora 29/Fedora 28上安装Gulp.js
时间:2020-02-23 14:30:42 来源:igfitidea点击:
在这篇博客文章中,我将带我们逐步完成在CentOS 7/Fedora 29/Fedora 28上安装Gulp.js的步骤。Gulp是一个工具包,可自动化开发工作流程中的繁琐或者耗时的任务。 Gulp集成了所有主要IDE中的集成功能,可轻松与PHP,.NET,Node.js,Java 等结合使用。
以下是在CentOS 7/Fedora 29/Fedora 28上安装Gulp.js的步骤。
安装Node.js
Gulp要求在主机系统上安装Node。在继续执行之前,请确保已将其安装在系统上。
请参阅如何在Linux上运行多个版本的Node.js
在CentOS 7上安装Node.js
curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash sudo yum install -y nodejs sudo yum install gcc-c++ make
在Fedora 29/Fedora 28上安装Node.js
对于Fedora 29/Fedora 28,请通过运行以下命令来安装Node.js。
安装V8 Javascript引擎:
sudo dnf install nodejs
要安装V11 Javascript Engine,请使用:
curl -sL https://rpm.nodesource.com/setup_11.x | sudo -E bash sudo dnf install -y nodejs sudo yum install gcc-c++ make
检查节点版本:
# node --version v11.1.0 $npx --version 6.4.1
第2步:在CentOS 7/Fedora 29/Fedora 28上安装Gulp.js
安装Node.js之后,继续在CentOS 7/Fedora 29/Fedora 28上安装installGulp.js。
sudo npm install --global gulp-cli
这将使gulplpto在系统上全局可用。
验证gulp版本:
$gulp --version [20:12:23] CLI version 2.0.1
在开发依赖项中安装gulp软件包
要在开发依赖项中安装gulp软件包,请按照以下步骤操作:
创建一个项目目录:
$npx mkdirp project1 npx: installed 2 in 1.355s
导航到Project目录并创建package.json文件
$cd project1 $ npm init
这将指导我们为项目命名,版本,描述等。示例输出如下:
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (project1)
version: (1.0.0)
description: My first Project
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /home/jmutai/project1/package.json:
{
"name": "project1",
"version": "1.0.0",
"description": "My first Project",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
在devDependencies中安装gulp软件包
npm install --save-dev theitroad@localhost
检查gulp版本:
$gulp --version [20:22:52] CLI version 2.0.1 [20:22:52] Local version 4.0.0
创建一个gulpfile
在项目根目录中创建一个名为gulpfile.js的文件:
vim gulpfile.js
添加以下内容:
function defaultTask(cb) {
//place code for your default task here
cb();
}
exports.default = defaultTask
通过在项目目录中运行gulp命令进行测试:
$gulp [20:25:17] Using gulpfile ~/project1/gulpfile.js [20:25:17] Starting 'default'... [20:25:17] Finished 'default' after 5.51 ms
要运行多个任务,可以使用gulp <task> <othertask>。

