-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
75 lines (64 loc) · 1.98 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
74
75
/**
* gulp配置文件
* */
var path = require('path');
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var minify = require('gulp-minify-css');
var livereload = require('gulp-livereload')
var rename = require("gulp-rename");
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var options = process.argv.slice(2) || [];
var themes = 'default';
if (options.length > 1 && options[0] == '--theme') {
themes = options[1];
}
console.log('~~~~~',themes)
var staticPath = path.join('./themes/', themes, './static');
var distPath = path.join(staticPath, './dist');
var srcOpts = {
buffer: true
};
var jsDir = 'javascripts';
var styDir = 'stylesheets';
// 默认任务
gulp.task('default', ['mini']);
// 压缩js/css任务
gulp.task('mini', ['clean'],function () {
// 压缩js
gulp.src([
staticPath + '/' + jsDir + '/jq.js',
staticPath + '/' + jsDir + '/bootstrap.js',
staticPath + '/' + jsDir + '/jq.pjax.js',
staticPath + '/' + jsDir + '/metisMenu.js',
staticPath + '/' + jsDir + '/fullImage.js',
staticPath + '/' + jsDir + '/doc.js'
], srcOpts)
.pipe(uglify())
.pipe(concat('docx.js'))
.pipe(gulp.dest(distPath + '/' + jsDir + '/'))
.pipe(livereload());
// 压缩css
gulp.src([staticPath + '/' + styDir + '/*.css', '!' + staticPath + '/' + styDir + '/*.min.css'])
.pipe(minify())
.pipe(concat('docx.css'))
.pipe(gulp.dest(distPath + '/' + styDir + '/'))
.pipe(livereload());
});
gulp.task('clean', function () {
return gulp.src([staticPath + '/dist/'], {read: false})
.pipe(clean());
});
gulp.task('watch', function () {
livereload.listen();
// 监听目录下的文件,若文件发生变化,则调用mini任务。
gulp.watch(
[
staticPath + '/' + jsDir + '/*.js',
staticPath + '/' + styDir + '/*.css',
path.join(__dirname, './views/*')
]
, ['mini']
);
});