-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
103 lines (93 loc) · 2.22 KB
/
gulpfile.babel.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import fs from 'fs';
import { src, dest, parallel, series, watch } from 'gulp';
import { rollup } from 'rollup';
import { babel } from '@rollup/plugin-babel';
import terser from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';
import rename from 'gulp-rename';
import cleanCSS from 'gulp-clean-css';
const files = {
js: './src/**/*.js',
css: './src/css/wysi.css',
icons: './assets/icons.svg',
dist: './dist',
bundle: {
input: './src/core.js',
output: './dist/wysi.js',
minified: './dist/wysi.min.js',
}
};
const fileHeader = '/*!\n'+
' * Copyright (c) 2023 Momo Bassit.\n'+
' * Licensed under the MIT License (MIT)\n'+
' * https://github.com/mdbassit/Wysi\n'+
' */';
const rollupInput = {
input: files.bundle.input,
external: ['window', 'document'],
plugins: [
replace({
preventAssignment: true,
values: {
_SVGIcons_: fs.readFileSync(files.icons).toString().replace(/>\s+</g,'><').trim()
}
}),
babel({
babelHelpers: 'bundled'
})
]
};
const rollupOuputs = [
// Normal output
{
file: files.bundle.output,
format: 'iife',
banner: fileHeader,
globals: {
window: 'window',
document: 'document',
}
},
// Minified output
{
file: files.bundle.minified,
plugins: [terser()],
format: 'iife',
sourcemap: true,
banner: fileHeader,
globals: {
window: 'window',
document: 'document',
}
}
];
function bundleJS() {
return rollup(rollupInput).then(bundle => {
return new Promise(async function (resolve, reject) {
for (const output of rollupOuputs) {
await bundle.write(output);
}
resolve();
});
});
}
function minifyCSS() {
return src(files.css)
.pipe(cleanCSS())
.pipe(rename(function (path) {
path.basename += '.min';
}))
.pipe(dest(`./${files.dist}`));
}
function copySourceCSS() {
return src(files.css).pipe(dest(files.dist));
}
function watchFiles() {
return new Promise(function (resolve, reject) {
watch(files.js, bundleJS);
watch(files.css, parallel(minifyCSS, copySourceCSS));
resolve();
});
}
export const build = parallel(bundleJS, minifyCSS, copySourceCSS);
export default series(build, watchFiles);