/
gulpfile.js
75 lines (65 loc) · 1.87 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var cssmin = require('gulp-clean-css');
var htmlmin = require('gulp-htmlmin');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var babel = require('rollup-plugin-babel');
var rollup = require('rollup').rollup;
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var intoStream = require('into-stream');
gulp.task('minify-html', function() {
return gulp.src('html/*')
.pipe(htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true
}))
.pipe(gulp.dest('build'))
});
gulp.task('build-css', function() {
return gulp.src('css/*')
.pipe(cssmin())
.pipe(concat('style.min.css'))
.pipe(gulp.dest('build/css'))
.pipe(reload({stream: true}));
})
gulp.task('build-js', function() {
return rollup({
entry: './js/index.js',
plugins: [
babel({
exclude: ['node_modules']
})
]
}).then(function(bundle) {
var result = bundle.generate({
format: 'cjs'
});
var bundler = browserify(intoStream(result.code));
bundler.bundle()
.on('error', console.error.bind(console))
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/js/'))
.pipe(reload({stream: true}));
});
});
gulp.task('build', ['minify-html', 'build-css', 'build-js', 'build-assets']);
gulp.task('build-assets', function() {
return gulp.src('./assets/**/*')
.pipe(gulp.dest('./build/assets'));
});
gulp.task('server', function() {
browserSync({
server: 'build'
});
});
gulp.task('start', ['build', 'server']);
gulp.task('watch', ['build', 'server'], function() {
gulp.watch('css/*', ['build-css']);
gulp.watch('html/*', ['minify-html', reload]);
gulp.watch('js/**', ['build-js'])
gulp.watch('assets/*', ['build-assets']);
});