This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
78 lines (71 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
76
77
78
const gulp = require('gulp')
const browserSync = require('browser-sync')
const reload = browserSync.reload
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const uglify = require('rollup-plugin-uglify')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const gzip = require('gulp-gzip')
const sourcemaps = require('gulp-sourcemaps');
const cssnano = require('gulp-cssnano');
// Static Server & watching files:
gulp.task('serve', ['build'], function () {
browserSync({
port: 4040,
server: {
open: false,
baseDir: './'
}
}).reload
})
gulp.task('watch', function() {
gulp.watch('./index.html').on('change', reload)
gulp.watch(['./dev/app.js', 'dev/**/*.js'], ['build', reload])
gulp.watch('./js/app.js').on('change', reload)
gulp.watch('./dev/css/*.css', ['build', reload])
})
gulp.task('build', function () {
gulp.src('./dev/css/styles.css')
.pipe(sourcemaps.init())
.pipe(cssnano({advanced: true, aggressiveMerging: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./css'))
return rollup.rollup({
input: './dev/app.js',
plugins: [
babel(),
resolve({
jsnext: true,
main: true,
browser: true
}),
commonjs(),
uglify({
compress: {
collapse_vars: true
}
})
]
})
.then((bundle) => {
return bundle.write({
format: 'iife',
name: 'app',
file: './js/app.js',
sourcemap: true
})
})
.then((bundle) => {
return gulp.src('./js/app.js')
.pipe(gzip({ extension: 'gzip' }))
.pipe(gulp.dest('./js'))
})
.then((bundle) => {
gulp.src('./css/styles.css')
.pipe(gzip({ extension: 'gzip' }))
.pipe(gulp.dest('./css'))
})
})
// Process app.js and load page in browser:
gulp.task('default', ['serve', 'watch'])