gulp commonly used commands

gulp commonly used commands:

  • Download gulp:npm i gulp

  • nrm (npm registry manager) is a mirror image of npm source management tool, sometimes foreign resources too slow, you can use this to quickly switch between the source npm

  • Create a task:gulp.task();

    Get file path need to perform character: gulp.src();

    Operations are required to be performed into the pipe()process

    Sends the processed files in the target path under:.gulp.pipe(gulp.dest())

    Use:

    // 目标: 复制 src/default.html 到 dist 目录下
    //1. 加载 gulp 模块
    //加载第三方模块,也只需要将模块名填入即可
      const gulp = require('gulp');
    //加载 gulp-htmlmin 模块,用来对html代码进行压缩
      const htmlmin = require('gulp-htmlmin');
    //加载 gulp-file-include 模块,用来引入html文件的公共区域
      const includeFile = require('gulp-file-include');
    
    //2. 编写任务 --- task 方法
    //参数1: 任务名称 --- 自定义
    //参数2: 回调函数 --- 因为gulp的版本原因,目前最新版需要加 async 进行修饰
    gulp.task('first', async () => {
        //指定要处理的文件,  使用 await 来修饰 gulp.src 方法
         await gulp.src('./src/default.html')
    //指定处理方式
    //dest方法就是将指定的文件复制到指定的位置
      .pipe(gulp.dest('./dist'))
    })

Guess you like

Origin www.cnblogs.com/j-j-h/p/11908628.html