-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
63 lines (53 loc) · 1.63 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
/* eslint-disable no-undef */
'use strict';
const destFolder = './dist';
const destNpmFolder = `${destFolder}/npm-package`;
const srcFolder = './src';
const destfilename = 'checkout.js'
const destBundlefilename = 'main.js'
const destFile = `${destFolder}/${destfilename}`;
const destBundleFile = `${srcFolder}/${destBundlefilename}`;
const packageJson = 'package.json';
const readme = 'README.md';
const { series, src, dest, watch } = require('gulp');
const rollup = require('rollup');
const uglify = require('gulp-uglify-es').default;
const rename = require('gulp-rename');
const babel = require('gulp-babel');
async function build() {
const bundle = await rollup.rollup({
input: destBundleFile
});
return await bundle.write({
file: destFile,
format: 'es',
name: destfilename,
sourcemap: true
});
}
function minify() {
return src(destFile)
.pipe(dest(destFolder))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(dest(destFolder));
}
function minifyES5(){
return src(destFile)
.pipe(babel({
presets: ["@babel/preset-env"]
}))
.pipe(rename(`checkout.es5.js`))
.pipe(dest(destFolder))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(dest(destFolder));
}
function generateNpmPackage(){
return src([destFile, packageJson, readme])
.pipe(dest(destNpmFolder));
}
exports.build = series(build, minify, minifyES5, generateNpmPackage);
exports.default = function(){
watch(['src/*.js', 'src/*/*.js'], { ignoreInitial: false }, series(build, minify, minifyES5));
};