Gulp

项目地址 https://github.com/LuckyChou710/ReStart-FE/tree/main/node/gulp

gulp 的基本使用

全局安装 gulp-cli 用于在命令行执行 gulp 命令

在项目中安装 gulp

yarn global add gulp-cli
yarn add gulp -D

gulp 的任务需要写在根目录下的 gulpfile.js

执行任务

// 基础使用
const task1 = (cb) => {
  setTimeout(() => {
    console.log('任务一执行了');
  }, 1000);
  cb();
};

module.exports = {
  task1,
};

然后在命令行输入 task1 即可执行 task1 任务

并行 / 串行

构建 css

安装 gulp-less gulp-clean-css

前者用于转换 less 后者用于压缩 css 注意两者在使用上有先后的依赖关系

构建 js

安装 gulp-uglify gulp-uglify

前者用于转换新的语法 后者用于压缩 js 代码

构建 html

安装 gulp-htmlmin 用于压缩 html 代码

部署服务

Last updated

Was this helpful?