-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·66 lines (56 loc) · 2.06 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
// based on https://gist.github.com/TravelingTechGuy/9996733
const gulp = require('gulp');
const clean = require('gulp-clean');
const cleanhtml = require('gulp-cleanhtml');
const cleancss = require('gulp-clean-css');
const eslint = require('gulp-eslint');
//const stripdebug = require('gulp-strip-debug');
//const uglify = require('gulp-uglify');
const zip = require('gulp-zip');
const manifest = require('./src/manifest');
// clean build directory
gulp.task('clean', () => gulp.src('build/*', { read: false })
.pipe(clean()));
// copy static folders to build directory
gulp.task('copy', () => {
gulp.src('src/icons/**')
.pipe(gulp.dest('build/icons'));
return gulp.src('src/manifest.json')
.pipe(gulp.dest('build'));
});
// copy and compress HTML files
gulp.task('html', () => gulp.src('src/*.html')
.pipe(cleanhtml())
.pipe(gulp.dest('build')));
// run scripts through ESLint
gulp.task('eslint', () => gulp.src('src/scripts/*.js')
.pipe(eslint({}))
.pipe(eslint.format()));
// copy vendor scripts and uglify all other scripts, creating source maps
gulp.task('scripts', gulp.series('eslint', (cb) => {
gulp.src(['src/scripts/**/*.js'])
//.pipe(stripdebug())
//.pipe(uglify({ outSourceMap: true }))
.pipe(gulp.dest('build/scripts'));
cb();
}));
// minify styles
gulp.task('styles', () => gulp.src('src/styles/**/*.css')
.pipe(cleancss({ level: 2 }))
.pipe(gulp.dest('build/styles')));
// build ditributable and sourcemaps after other tasks completed
gulp.task('zip', gulp.series('html', 'scripts', 'styles', 'copy', (cb) => {
const distFileName = `${manifest.name} v${manifest.version}.zip`;
const mapFileName = `${manifest.name} v${manifest.version}-maps.zip`;
// collect all source maps
gulp.src('build/scripts/**/*.map')
.pipe(zip(mapFileName))
.pipe(gulp.dest('dist'));
// build distributable extension
gulp.src(['build/**', '!build/scripts/**/*.map'])
.pipe(zip(distFileName))
.pipe(gulp.dest('dist'));
cb();
}));
// run all tasks after build directory has been cleaned
gulp.task('default', gulp.series('clean', 'zip'));