-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
54 lines (45 loc) · 1.28 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
'use strict'
const babelify = require('babelify')
const browserify = require('browserify')
const del = require('del')
const gulp = require('gulp')
const merge2 = require('merge2')
const uglify = require('gulp-uglify')
const path = require('path')
const runSequence = require('run-sequence')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
function bundle (indexFile, dir, deps, cb) {
let stream = merge2(
browserify(indexFile, { debug: true })
.transform(babelify)
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(dir))
)
for (let key in deps) {
stream.add(
gulp.src(key)
.pipe(gulp.dest(path.join(dir, deps[key])))
)
}
stream.on('queueDrain', cb)
}
function createTasks (name) {
gulp.task(`clean-${name}`, () => del(`./build/${name}`, { force: true }))
gulp.task(`build-${name}`, (cb) => {
bundle('./src/shared/index.js', `./build/${name}`, {
[`./src/${name}/manifest.json`]: '',
'./src/shared/content.js': '',
'./src/shared/images/*': 'images',
'./src/shared/popup/*': 'popup'
}, cb)
})
gulp.task(name, (cb) => {
runSequence(`clean-${name}`, `build-${name}`, cb)
})
}
createTasks('firefox')
createTasks('chrome')