-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
77 lines (65 loc) · 2.15 KB
/
gulpfile.mjs
File metadata and controls
77 lines (65 loc) · 2.15 KB
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
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import strip from "@rollup/plugin-strip";
import terser from "@rollup/plugin-terser";
import gulp from "gulp";
import { rimraf } from "rimraf";
import { rollup } from "rollup";
const babelConfig = {
babelHelpers: "bundled",
ignore: ["node_modules"],
compact: false,
extensions: [".js"],
presets: [
[
"@babel/preset-env",
{
corejs: 3,
useBuiltIns: "usage",
modules: false,
targets: {
browsers: [
"last 2 Chrome versions",
"last 2 Safari versions",
"last 2 iOS versions",
"last 2 Firefox versions",
"last 2 Edge versions",
],
},
},
],
],
ignore: [/node_modules\/(?!(highlight\.js|marked)\/).*/],
};
const debugRollupPlugins = [resolve(), commonjs(), babel(babelConfig), terser()];
const prodRollupPlugins = [resolve(), commonjs(), strip(), babel(babelConfig), terser()];
async function compile(variant) {
const rollupPlugins = variant === "debug" ? debugRollupPlugins : prodRollupPlugins;
const rollupOutputName = variant !== "prod" ? `plugin.${variant}.js` : `plugin.js`;
const rollupOutputFormat = variant === "esm" ? "es" : "umd";
const builder = await rollup({
input: `./src/plugin.js`,
plugins: rollupPlugins,
});
await builder.write({
file: `./dist/${rollupOutputName}`,
name: "RevealCaffeine",
format: rollupOutputFormat,
});
}
// Creates a UMD and ES module bundle for each plugin
export async function plugins() {
await Promise.all(["debug", "esm", "prod"].map(compile));
}
// npm run clean / npx gulp clean: clean 'dist' folder
export const clean = () => rimraf("./dist/");
// npm run build / npx gulp build: build plugins
export const build = gulp.series(clean, plugins);
// watch files for changes and trigger rebuild tasks
async function watchFiles() {
gulp.watch("src/**/*.js", plugins);
}
// npm run watch / npx gulp watch: continuously update index.html from deps
export const watch = gulp.series(build, watchFiles);
export default build;