-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (86 loc) · 2.33 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//gulp 2015-02-27
/**
* Concat, rename, minify
*
* @param {String} ext
* @param {String} name
* @param {Object} opt
*/
'use strict';
var gulp = require('gulp');
var g = require('gulp-load-plugins')({lazy: false}),
browserSync = require('browser-sync'),
reload = browserSync.reload;
var config = {
paths: {
html: {
src: ["src/**/*.html"],
dest: "build"
},
js: {
src: ["src/app/**/*.js"],
dest: "build/js"
},
css: {
src: ["src/assets/**/*.css"],
dest: "build/css"
},
assets: {
src: ["src/assets/**/*.png", "src/assets/**/*.jpg"],
dest: "build/assets"
}
}
}
// Watch Files For Changes & Reload
gulp.task('default', function () {
browserSync({
notify: false,
// Run as an https by uncommenting 'https: true'
// Note: this uses an unsigned certificate which on first access
// will present a certificate warning in the browser.
// https: true,
server: ['src']
});
gulp.watch(config.paths.html.src, reload);
gulp.watch(config.paths.css.src,reload, ['inject']);
gulp.watch(config.paths.js.src, ['inject']);
gulp.watch(config.paths.assets.src, reload);
});
// inject css js
gulp.task('inject', function(){
return gulp.src('./src/index.html')
.pipe(g.inject(gulp.src('./src/app/**/*.js', {read: false}), {relative: true}))
.pipe(g.inject(gulp.src('./src/assets/css/*.css', {read: false}), {relative: true}))
.pipe(gulp.dest('./src'));
})
/**
* Dist
*/
// 检查脚本
gulp.task('jscheck', function() {
gulp.src(config.paths.js.src)
.pipe(g.jshint())
.pipe(g.jshint.reporter('default'));
});
// 合并,压缩js文件
gulp.task('minjs', function() {
gulp.src(config.paths.js.src)
.pipe(g.concat('app.js'))
.pipe(gulp.dest('./dist'))
.pipe(g.rename('app.min.js'))
.pipe(g.uglify())
.pipe(gulp.dest('./dist'));
});
// 合并,压缩css文件
gulp.task('mincss', function() {
gulp.src(config.paths.js.src)
.pipe(g.concat('app.css'))
.pipe(gulp.dest('./dist'))
.pipe(g.rename('app.min.css'))
.pipe(g.cssmin())
.pipe(gulp.dest('./dist'));
});
// 默认任务
gulp.task('dist', function(){
gulp.run('jscheck', 'minjs', 'mincss');
});