-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
49 lines (41 loc) · 1.13 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
'use strict'
const babelify = require('babelify')
const browserify = require('browserify')
const del = require('del')
const gulp = require('gulp')
const merge2 = require('merge2')
const path = require('path')
const runSequence = require('run-sequence')
const source = require('vinyl-source-stream')
function bundle (indexFile, dir, deps, cb) {
let stream = merge2(
browserify(indexFile, { debug: false })
.transform(babelify)
.bundle()
.pipe(source('bundle.js'))
.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/index.js', `./build/${name}`, {
[`./src/manifest.json`]: '',
'./src/content.js': '',
'./src/images/*': 'images',
'./src/popup/*': 'popup'
}, cb)
})
gulp.task(name, (cb) => {
runSequence(`clean-${name}`, `build-${name}`, cb)
})
}
createTasks('chrome')
createTasks('firefox')