-
Notifications
You must be signed in to change notification settings - Fork 18
/
gulpfile.js
69 lines (62 loc) · 1.64 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
const babel = require('gulp-babel')
const del = require('del')
const gulp = require('gulp')
const plumber = require('gulp-plumber')
const rename = require('gulp-rename')
const sequence = require('run-sequence')
const uglify = require('gulp-uglify')
const webpack = require('webpack-stream')
const sourcemaps = require('gulp-sourcemaps')
const srcDir = './src'
const srcGlob = `${srcDir}/*.js`
const srcEntry = `channel.js`
const distDir = './dist'
const distUmdDir = `${distDir}/umd`
const distCjsDir = `${distDir}/cjs`
const singleFilename = 'async-csp.js'
const libraryName = 'async-csp'
function transpileUmd(config) {
if (config === undefined) {
config = {
output: {
filename: singleFilename,
library: libraryName,
libraryTarget: 'umd',
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
],
},
}
}
return webpack(config)
}
gulp.task('clean', done => {
return del([distDir], done)
})
gulp.task('build:umd', () => {
return gulp
.src(`${srcDir}/${srcEntry}`)
.pipe(transpileUmd())
.pipe(sourcemaps.init())
.pipe(gulp.dest(distUmdDir))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(distUmdDir))
})
gulp.task('build:cjs', () => {
return gulp
.src(srcGlob)
.pipe(plumber())
.pipe(babel()) // config in .babelrc
.pipe(plumber.stop())
.pipe(gulp.dest(distCjsDir))
})
gulp.task('build', done => {
sequence(['build:cjs', 'build:umd'], done)
})
gulp.task('default', done => {
sequence('test', 'clean', 'lint', 'build', 'watch', done)
})