-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
104 lines (80 loc) · 2.59 KB
/
gulpfile.babel.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
99
100
101
102
103
104
/**
* webapp
* By Julian
* @ zanjser@163.com
* 2016年06月12日16:44:43
*/
import pkg from './package.json';
import gulp from 'gulp';
import sass from 'gulp-sass';
import concat from 'gulp-concat';
import minifycss from 'gulp-minify-css';
import uglify from 'gulp-uglify';
import rename from 'gulp-rename';
import notify from 'gulp-notify';
import imagemin from 'gulp-imagemin';
import header from 'gulp-header';
import autoprefixer from 'gulp-autoprefixer';
import px2rem from 'gulp-px3rem';
const day = '20160612', mincss = 'app.css', minjs = 'app.js';
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
const banner = [
'/*! ',
'<%= pkg.name %> ',
'v<%= pkg.version %> | ',
`(c) ${new Date()} <%= pkg.author %> |`,
' <%= pkg.homepage %>',
' */',
'\n'
].join('');
//编译Sass,Autoprefix及缩小化
gulp.task('sass', () => gulp.src(`./${day}/src/scss/main.scss`)
.pipe(sass({ style: 'expanded' }))
.pipe(gulp.dest(`./${day}/.tmp/css`))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(px2rem())
.pipe(rename(mincss))
.pipe(gulp.dest(`./${day}/.tmp/`))
.pipe(minifycss())
.pipe(header(banner, { pkg }))
.pipe(gulp.dest(`./${day}/build/css/`))
.pipe(reload({stream: true}))
.pipe(notify({ message: 'Styles task complete' })));
gulp.task('scripts',() => gulp.src(`./${day}/src/js/*.js`)
.pipe(concat(minjs))
.pipe(gulp.dest(`./${day}/.tmp/js`))
.pipe(uglify())
.pipe(header(banner, { pkg }))
.pipe(gulp.dest(`./${day}/build/js/`))
.pipe(reload({stream: true}))
.pipe(notify({ message: 'Scripts task complete' })));
gulp.task('images', () => {
return gulp.src(`./${day}/src/images/*`)
.pipe(imagemin())
.pipe(gulp.dest(`./${day}/build/images`));
});
gulp.task('html',() => {
gulp.src(`./${day}/*.html`)
.pipe(reload({stream: true}))
});
// 静态服务器 + 监听 scss/html 文件
gulp.task('dev', ['sass'], () => {
browserSync.init({
server: `./${day}/`
});
// 看守.scss 档
gulp.watch(`./${day}/src/scss/*.scss`, ['sass']);
gulp.watch('./home/scss/*.scss', ['home']);
// 看守所有.js档
gulp.watch(`./${day}/*.js`, ['scripts']);
gulp.watch(`./${day}/src/js/*.js`, ['html','scripts']);
gulp.watch(`./${day}/src/images/*`, ['images']);
// 看守所有.html
gulp.watch(`./${day}/*.html`).on('change', reload);;
gulp.watch('./*.html').on('change', reload);;
});
gulp.task('default', ['dev']);