Gulp4 前端自动化工做流配置

本文首发于 我的博客:蓝色梦想。若是你刚接触 Gulp,能够查看我之前写的文章 Gulp构建前端自动化工做流(Gulp入门介绍)css

随着最近把 nodejs 从 8.x 升级到了 10.x,发现 Gulp3.x 早已经不能兼容新版的 node,而且环境中的部分依赖,也已经被淘汰。 因而趁此机会,把 Gulp 升级为 4.x 版本,并把整个环境从新改造了一下。html

现已经发布至 Github 和 NPM 做为不按期维护的一个项目。关于后续更新和维护状况,请关注本项目的:GitHubNPM前端

简介(Introduction)

简单实用的前端自动化工做流配置,基于 Gulp4.xnode

Simple and practical front-end automated workflow configuration based on Gulp4.xgit

特性(Features)

  • SASS (CSS preprocessor)
  • 图像压缩和转Base64 (Images compress & save base64 image)
  • JS压缩 (JavaScript compressor)
  • 热加载 (Hot reload)
  • 一套环境多项目共存 (Multi-Project Builds)

目录结构(Directory structure)

+ project_file_name                 // Project folder(Example)
    + Build                         // Production folder(Output floder)
        - etc...
    + dist                          // Pevelopment folder(Output floder)
        - etc...
    + dist__test                    // Test folder(Output floder)
        - etc...
    + src                           // Source code
        - images                    // Image folder
        - js                        // Script folder
        - lib                       // CSS/JS library
        - scss                      // Style folder
        - project.config.js         // Project custom config
- .gitignore                        // Exclude files from git
- gulp.config.js                    // Gulp custom config
- gulpfile.js                       // Gulp config
- package.json                      // Dependency & Module list
- README.md                         // Documentation
- yarn.lock                         // Yarn
复制代码

环境要求(Pre Required)

若是你已经全局安装了 gulp 请先删除旧版本后再安装github

If you've previously installed gulp globally, please remove the old versionnpm

$ npm rm --global gulp
# or
$ yarn global remove gulp
复制代码

全局安装 gulp-cli Install the gulp command line utilityjson

$ npm install --global gulp-cli
# or
$ yarn global add gulp-cli
复制代码

安装方式(Installation)

# 安装 - Using npm or yarn
$ npm i ublue-gulp-config
# or
$ yarn add ublue-gulp-config
复制代码
# 安装依赖 - Install dependency
$ npm install
# or
$ yarn install
复制代码

使用方法(Used)

# 项目初始化 - Project initialization
$ gulp init

# 环境启动 - Start it
$ gulp
复制代码

环境切换(Using environment variables)

# 发布测试环境 - Build for test environment
$ gulp init --test

# 发布生产环境 - Build for production environment
$ gulp init --build

# 清理生产目录 - Clean up development or production
$ gulp clean

# 清理指定环境目录 - Clean up the specified environment directory
$ gulp clean --test
复制代码

开源许可(License)

MITgulp

相关文章
相关标签/搜索