This repository has been 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
/
gulpfile.js
113 lines (102 loc) · 2.78 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// @ts-nocheck
const gulp = require('gulp')
const browserSync = require('browser-sync')
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
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('cssnano');
const postcss = require('gulp-postcss')
const pkg = require('./package.json')
const minify = require('rollup-plugin-babel-minify')
gulp.task('build:js', function (done) {
rollup.rollup({
input: './src/js/app.js',
plugins: [
babel(),
resolve({
jsnext: true,
main: true,
browser: true
}),
commonjs(),
minify({
mangle: { topLevel: true },
comments: false
})
]
})
.then((bundle) => {
return bundle.write({
format: 'iife',
name: 'app',
file: './dist/js/app.js',
sourcemap: true
})
})
.then((bundle) => {
return gulp.src('./dist/js/app.js')
.pipe(gzip({ extension: 'gzip' }))
.pipe(gulp.dest('./dist/js'))
})
.then((bundle) => {
done();
})
})
gulp.task('build:css', function (done) {
const plugins = [cssnano({ advanced: true, aggressiveMerging: false })]
gulp.src('./src/css/*.css')
.pipe(sourcemaps.init())
.pipe(postcss(plugins))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/css'))
gulp.src('./dist/css/*.css')
.pipe(gzip({ extension: 'gzip' }))
.pipe(gulp.dest('./dist/css'))
done()
})
gulp.task('move-images', function (done) {
gulp.src(['./src/images/*', './src/images/**/*'])
.pipe(gulp.dest('./dist/images'))
done()
})
const server = browserSync.create();
function reload() {
server.reload();
}
function serve(done) {
setTimeout(() => {
server.init({
port: 4040,
server: {
open: false,
baseDir: './'
}
})
done()
}, 250)
}
gulp.task('watch', function (done) {
gulp.watch('./index.html').on('change', reload)
gulp.watch(['./src/js/app.js', 'src/js/**/*']).on('change', gulp.series('build:js', reload))
gulp.watch('./src/css/*.css').on('change', gulp.series('build:css', reload))
done()
})
// Process app.js and load page in browser:
gulp.task('default', gulp.series('build:js', 'build:css', 'move-images', 'watch', serve), function (done) {
done()
})
gulp.task('fresh-build', gulp.series('build:js', 'build:css', 'move-images'), function (done) {
done()
})
// Create production-ready version of this project.
gulp.task('production', function (done) {
const name = pkg.name + '-production'
gulp.src(['./dist/**/*', './dist/**/**/*'])
.pipe(gulp.dest(`../${name}/dist`))
gulp.src('./index.html')
.pipe(gulp.dest(`../${name}`))
done()
})