-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
110 lines (93 loc) · 2.39 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
105
106
107
108
109
110
import gulp from 'gulp';
import sass from 'gulp-sass';
import autoprefix from 'gulp-autoprefixer';
import plumber from 'gulp-plumber';
import connect from 'gulp-connect';
import babel from 'gulp-babel';
import del from 'del';
import usemin from 'gulp-usemin';
import uglify from 'gulp-uglify';
import htmlminify from 'gulp-html-minify';
import 'babel-polyfill';
import rev from 'gulp-rev';
let base = {
src: './src/',
dest: 'build/'
};
let styleBase = {
src: base.src + '/style/*.scss',
devDest: ".tmp/style",
buildDest: base.dest
};
let scriptBase = {
src: base.src + '/js/js.js',
devDest: ".tmp/js",
buildDest: base.dest
};
gulp.task('dev-styles', () => {
return gulp.src(styleBase.src)
.pipe(plumber())
.pipe(sass())
.pipe(autoprefix({
browsers: ['> 1%', 'last 4 Android versions']
}))
.pipe(gulp.dest(styleBase.devDest))
.pipe(connect.reload());
});
gulp.task('dev-scripts', () => {
return gulp.src(scriptBase.src)
.pipe(plumber())
.pipe(babel({
presets: ['es2015'],
plugins: ["babel-polyfill"]
}))
.pipe(gulp.dest(scriptBase.devDest))
.pipe(connect.reload());
});
gulp.task('build-scss', () => {
return gulp.src([styleBase.src])
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefix({
browsers: ['> 1%', 'last 4 Android versions']
}))
.pipe(gulp.dest(styleBase.devDest));
});
gulp.task('dev-connect', () => {
connect.server({
host: "0.0.0.0",
port: 8888,
livereload: true,
root: ['.tmp/', 'src/']
})
});
gulp.task('dev-watch', () => {
gulp.watch(styleBase.src, ['dev-styles']);
gulp.watch(scriptBase.src, ['dev-scripts']);
});
gulp.task('dev', ['dev-connect', 'dev-styles', 'dev-scripts', 'dev-watch']);
gulp.task('clean', (cbk) => {
del([base.dest, '.tmp'], {force: true}, cbk);
});
gulp.task('usemin', ['build-scss'], () => {
return gulp.src('src/index.html')
.pipe(usemin({
style: [rev()],
es6: [babel(), uglify(), rev()]
}))
.pipe(htmlminify())
.pipe(gulp.dest('build/'));
});
gulp.task('copy-assets', function () {
return gulp.src(['src/assets/**'], {base: 'src/assets'})
.pipe(gulp.dest('build/assets/'));
});
gulp.task('test-connect', function () {
connect.server({
root: ['build/'],
port: 9000
});
});
gulp.task('build',
['clean', 'usemin', 'copy-assets']
);
gulp.task('test', ['build', 'test-connect']);