-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.babel.js
110 lines (97 loc) · 2.53 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 { merge } from 'event-stream';
import browserify from 'browserify';
import watchify from 'watchify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import gulpLoadPlugins from 'gulp-load-plugins';
const $ = gulpLoadPlugins();
const sourceFolder = 'src/assets/js/';
const distFolder = 'dist/assets/js';
const files = [
'content-script.js',
'popup.js',
'options.js'
];
const buildDev = () => {
const tasks = files.map(
(file) => {
let bundler = browserify({
entries: `${sourceFolder}${file}`,
debug: true
});
const bundle = () => bundler
.transform('babelify', {
sourceMaps: false,
presets: ['@babel/preset-env'],
plugins: [
['@babel/transform-runtime'],
['transform-vue-template']
],
global: true,
ignore: [/[/\\]core-js/, /@babel[/\\]runtime/],
compact: false
})
.bundle()
.on('error', (error) => {
console.error(`Error: ${error.toString()}`);
})
.pipe(source(file))
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.sourcemaps.write('./'))
.pipe(gulp.dest(distFolder));
bundler = watchify(bundler);
bundler.on('update', () => {
bundle();
console.log(`Building ${sourceFolder}${file}...`);
});
bundler.on('bytes', (bytes) => {
console.log(`${sourceFolder}${file} build finish! (Size: ${bytes / 1024}kb)`);
});
return bundle();
}
);
return merge(...tasks);
};
const buildProd = () => {
const tasks = files.map(
file => browserify({
entries: `${sourceFolder}${file}`
})
.transform('babelify', {
presets: ['@babel/preset-env'],
plugins: [
['@babel/transform-runtime'],
['transform-vue-template']
],
comments: false,
global: true,
ignore: [/[\/\\]core-js/, /@babel[\/\\]runtime/],
compact: false
})
.bundle()
.on('error', (error) => {
console.error(`Error: ${error.toString()}`);
})
.pipe(source(file))
.pipe(buffer())
.pipe($.uglify({
mangle: false,
output: {
ascii_only: true
}
}))
.pipe(gulp.dest(distFolder))
);
return merge(...tasks);
};
gulp.task('dev-js', (done) => {
buildDev();
done();
console.log(`Watching ${sourceFolder}`);
});
gulp.task('build-js', (done) => {
buildProd();
done();
});