雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

在 CentOS/Fedora/Ubuntu/Debian 上安装 Gulp.js

2024-06-27 56

在这篇博文中,我将引导您完成在 CentOS/Fedora/Ubuntu 和 Debian Linux 上安装 Gulp.js 的步骤。 Gulp 是一个工具包,可帮助您自动执行开发工作流程中痛苦或耗时的任务。 Gulp 已集成到所有主要 IDE 中,以便于与 PHP、.NET、Node.js、Java 等一起使用。

第 1 步:安装 Node.js

Gulp 需要在托管系统上安装 Node。在继续步骤 2 之前,请确保它已安装在您的系统上。

请参阅下面有关安装的指南

  • 如何在 Linux 上运行多个版本的 Node.js

确认系统上的 Node.js。

$ node -v
v20.9.0

还要确认 npx 安装的版本。

$ npx --version
10.1.0

第 2 步:使用 npm 安装 Gulp.js

安装 Node.js 后,继续使用 Node 的 NPM 包管理器安装 Gulp.js

npm install --global gulp-cli

这将使 gulp 在系统上全局可用。

验证您的 gulp 版本:

$ gulp --version
CLI version: 2.3.0
Local version: Unknown

第 3 步:安装在您的开发依赖项中

要在您的开发依赖项中安装 gulp 包,请执行以下操作:

创建项目目录:

$ npx mkdirp project1
Need to install the following packages:
[email 
Ok to proceed? (y) y

导航到项目目录并创建 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"
}

在您的开发依赖项中安装 gulp 包

npm install --save-dev gulp

检查 gulp 版本:

$ gulp --version
CLI version: 2.3.0
Local version: 4.0.2

创建一个 gulp 文件

在项目根目录中创建一个名为 gulpfile.js 的文件:

vim gulpfile.js

添加这些内容:

function defaultTask(cb) {
  // place code for your default task here
  cb();
}

exports.default = defaultTask

通过在项目目录中运行 gulp 命令进行测试:

$ gulp
[02:41:28] Using gulpfile ~/project1/gulpfile.js
[02:41:28] Starting 'default'...
[02:41:28] Finished 'default' after 3.9 ms

要运行多个任务,可以使用 gulp


更新于:2个月前
赞一波!3

文章评论

全部评论