構建環(huán)境
1. 全局安裝 gulp
$ npm install --global gulp
2. 創(chuàng)建GulpDemo文件夾且進入文件夾
$ mkdir GulpDemo && cd GulpDemo
3. 在項目中引導創(chuàng)建一個package.json文件
$ npm init
package.json
4. 作為項目的開發(fā)依賴(devDependencies)安裝
$ npm install --save-dev gulp
5. 在項目根目錄下創(chuàng)建一個名為 gulpfile.js 的文件并打開此文件
$ touch gulpfile.js && open gulpfile.js
6. 在gulpfile.js 的文件中以下代碼
const gulp = require('gulp');
/**
* 定義一個任務
* 第一個參數(shù)為任務名
* 第二個參數(shù)為任務體
*/
gulp.task('hello', function(){
console.log('hello yangxiaoping');
//這里編寫一些重復性的流程
});
7. 運行hello任務
$ gulp hello
運行結果