-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
74 lines (61 loc) · 2.02 KB
/
gulpfile.mjs
File metadata and controls
74 lines (61 loc) · 2.02 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
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",
{
targets: {
node: "current",
},
},
],
],
};
const debugRollupPlugins = [resolve(), commonjs(), babel(babelConfig)];
const prodRollupPlugins = [resolve(), commonjs(), strip(), babel(babelConfig), terser()];
async function compile(variant) {
const rollupPlugins = variant === "debug" ? debugRollupPlugins : prodRollupPlugins;
const rollupOutputName = variant !== "prod" ? `index.${variant}.js` : `index.js`;
const builder = await rollup({
input: `./src/index.js`,
plugins: rollupPlugins,
external: ["sharp"],
});
await builder.write({
file: `./dist/${rollupOutputName}`,
name: "gulp-sharp",
format: "esm",
});
}
// Creates ES module bundles
export async function buildFlavors() {
await Promise.all(["debug", "prod"].map(compile));
}
export function copyTSDefinition() {
return gulp
.src("src/**/*.d.ts", { base: "src/", allowEmpty: true, encoding: false })
.pipe(gulp.dest("dist/", { mode: 0o644, dirMode: 0o755 }));
}
// npm run clean / npx gulp clean: clean 'dist' folder
export const clean = () => rimraf("./dist/");
// npm run build / npx gulp build: build plugin
export const build = gulp.series(clean, buildFlavors, copyTSDefinition);
// watch files for changes and trigger rebuild tasks
async function watchFiles() {
gulp.watch("src/**/*.js", buildFlavors);
gulp.watch("src/**/*.ts", buildFlavors, copyTSDefinition);
}
// npm run watch / npx gulp watch: continuously update index.html from deps
export const watch = gulp.series(build, watchFiles);
export default build;