-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathGulpfile.js
74 lines (68 loc) · 1.79 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
70
71
72
73
74
// Gulp
const gulp = require('gulp')
const plumber = require('gulp-plumber')
const file = require('gulp-file')
const filter = require('gulp-filter')
const uglify = require('gulp-uglify-es').default
const clean = require('gulp-clean')
const mergeStream = require('merge-stream')
// Rollup
const { rollup } = require('rollup')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const { getBabelOutputPlugin } = require('@rollup/plugin-babel')
// Const
const buildPath = 'dist/'
/**
* Generate scripts with commonjs module
* @param {import('rollup').RollupBuild} bundle
*/
/**
* Bundle index.js using rollup + babel
*/
async function bundle(name, format) {
const bundle = await rollup({
input: 'src/index.js',
plugins: [
nodeResolve({ browser: true }),
getBabelOutputPlugin({
allowAllFormats: true,
presets: [['@babel/preset-env', { modules: 'auto' }]],
// sourceMaps: true,
}),
],
})
return bundle.generate({
format: format,
name: name,
})
}
gulp.task('build', async function () {
const esmbundle = await bundle('VueAxios', 'esm')
const commonbundle = await bundle('VueAxios', 'umd')
const f = filter(['*', '!**/*.js.map'], { restore: true })
const data = {
'vue-axios.common.min.js': commonbundle,
'vue-axios.esm.min.js': esmbundle,
}
var stream = mergeStream()
for (const [name, bundle] of Object.entries(data)) {
stream.add(
file(name, bundle.output.map((o) => o.code).join(' '), {
src: true,
})
.pipe(plumber())
.pipe(f)
.pipe(uglify())
.pipe(gulp.dest(buildPath)),
)
}
return stream;
})
gulp.task('clean', function () {
return gulp.src('dist/*').pipe(
clean({
force: true,
}),
)
})
gulp.task('default', gulp.series('clean', 'build'))