gulp

Posted GIScript

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gulp相关的知识,希望对你有一定的参考价值。

 基于流的自动化构建工具

//项目目录下执行
npm install gulp

//安装依赖
gulp combo.js

//压缩文件
npm run build

  

 

 

 

//package.json文件
{
  "name": "myname",
  "version": "1.0",
  "description": "",
  "main": "index.js",
  "scripts":
  {"build": "gulp combojs && gulp combocss"
  },
  "author": "",
  "license": "",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-alias-combo": "^0.3.0",
    "gulp-concat": "^2.6.0",
    "gulp-minify-css": "^1.2.4",
    "gulp-ng-annotate": "^2.0.0",
    "gulp-ngmin": "^0.3.0",
    "gulp-notify": "^2.2.0",
    "gulp-rename": "^1.2.2",
    "gulp-uglify": "^1.5.4"
  }
}

  

//gulpfile.js文件

var gulp = require(‘gulp‘);
var uglify = require(‘gulp-uglify‘);//js压缩
var concat = require(‘gulp-concat‘);//文件合并
var rename = require(‘gulp-rename‘);//文件更名
var notify = require(‘gulp-notify‘);//提示信息
var cssmin = require(‘gulp-minify-css‘); //压缩css

gulp.task(‘combojs‘, function () {
    return gulp.src([
        ‘./angular/angular.js‘,
        ‘./jquery/jquery.js‘,
        ‘./js/bootstrap.js‘,
        ‘./js/bootstrap-switch.js‘,
        ‘./toastr/toastr.js‘,
        ‘./js/ui-bootstrap-tpls.min.js‘,
        ‘./js/tm.pagination.js‘,
        ‘./js/app.js‘,
        ‘./js/post.js‘

    ])
        .pipe(concat(‘all.js‘))
        .pipe(gulp.dest(‘./src/js‘))
        .pipe(rename({suffix: ‘.min‘}))
        .pipe(uglify())
        .pipe(gulp.dest(‘./src/js‘));
});

gulp.task(‘combocss‘, function () {
    return gulp.src([
        ‘./css/bootstrap.css‘,
        ‘./css/bootstrap3/bootstrap-switch.css‘,
        ‘./css/fontello.css‘,
        ‘./toastr/toastr.css‘,
        ‘./css/app.css‘
    ])
        .pipe(concat(‘all.css‘))
        .pipe(gulp.dest(‘./src/css‘))
        .pipe(rename({suffix: ‘.min‘}))
        .pipe(cssmin())
        .pipe(gulp.dest(‘./src/css‘));
});

gulp.task(‘default‘, [‘combocss‘, ‘combojs‘], function () {
    console.log(‘gulp完成!‘);
});

  

以上是关于gulp的主要内容,如果未能解决你的问题,请参考以下文章

gulp 项目构建 代码压缩与混淆

使用gulp进行代码压缩

gulp

gulp压缩构建代码

在 vs 代码中打开项目时未检测到 Gulp 任务

Gulp/Typescript/Async/Await 代码不起作用 - 为啥?