forked from LuRenJiasWorld/WP-Editor.md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (67 loc) · 2.4 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Defining requirements
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var watch = require('gulp-watch');
var cssnano = require('gulp-cssnano');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var merge2 = require('merge2');
var imagemin = require('gulp-imagemin');
var ignore = require('gulp-ignore');
var rimraf = require('gulp-rimraf');
var clone = require('gulp-clone');
var merge = require('gulp-merge');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var del = require('del');
var cleanCSS = require('gulp-clean-css');
var gulpSequence = require('gulp-sequence');
var replace = require('gulp-replace');
var autoprefixer = require('gulp-autoprefixer');
// Configuration file to keep your code DRY
var cfg = require('./gulpconfig.json');
var paths = cfg.paths;
// 压缩 js 文件
// 在命令行使用 gulp script 启动此任务
gulp.task('jscompress', function () {
// 1. 找到文件
return gulp.src('assets/Config/editormd.js')
.pipe(uglify()) //压缩
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(rename({suffix: '.min'})) //重命名
.pipe(gulp.dest('assets/Config')); //另存文件
});
// 压缩 css 文件
// 在命令行使用 gulp csscompress 启动此任务
gulp.task('csscompress', function () {
return gulp.src('assets/Config/editormd.css')
.pipe(cleanCSS({compatibility: '*'})) //压缩
.pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(rename({suffix: '.min'})) //重命名
.pipe(cssnano({discardComments: {removeAll: true}})) //压缩
.pipe(gulp.dest('assets/Config')); //另存文件
});
// 启动browser-sync服务
// 在命令行使用 gulp browser-sync 启动此任务
gulp.task('browser-sync', function () {
browserSync.init(cfg.browserSyncWatchFiles, cfg.browserSyncOptions);
});
// 启动监视服务
// 在命令行使用 gulp watch 启动此任务
gulp.task('watch', ['browser-sync'], function () {
gulp.watch('assets/Config/editormd.js', ['jscompress']);
gulp.watch('assets/Config/editormd.css', ['csscompress']);
});
// 默认任务
gulp.task('default', ['watch']);