-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
101 lines (92 loc) · 2.46 KB
/
esbuild.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
import { sassPlugin } from "esbuild-sass-plugin";
import pkg from "./package.json" assert { type: "json" };
import esbuild from "esbuild";
import { dev } from "local-dev-server";
import fs from "fs";
import path from "path";
let [mode] = process.argv.splice(2) ?? "prod";
export const outputRoot = `./dist`;
//export const outputRoot = `D:\\开发\\RuoYi-Vue-master\\rouyi-omii\\es-lib\\omii-ui\\latest`
//export const outputRoot = `../es-lib/omii-ui/${pkg.version}`
let outfile = `${outputRoot}/omii-ui.js`;
let defaultOptions = {
jsxFactory: "h",
jsxFragment: "h.f",
format: "esm",
bundle: true,
sourcemap: true,
minify: true,
};
const buildOptions = {
...defaultOptions,
entryPoints: ["src/index.jsx"],
outfile,
plugins: [
sassPlugin({
type: "css-text",
sourceMap: false,
style: "compressed",
}),
],
};
//minify sortablejs
esbuild.build({
...buildOptions,
entryPoints: ["node_modules/sortablejs/modular/sortable.core.esm.js"],
outfile: `${outputRoot}/sortablejs/sortable.core.esm.js`,
});
//tinymce copy
fs.cpSync("node_modules/tinymce", path.join("./dist", "tinymce"), {
recursive: true,
});
fs.cpSync("src/tinymce/langs", path.join("./dist", "tinymce/langs"), {
recursive: true,
});
//echarts copy
fs.cpSync("node_modules/echarts/dist", path.join("./dist", "echarts"), {
recursive: true,
});
switch (mode) {
case "prod":
esbuild.build(buildOptions);
// for (let editorOption of editorOptions) {
// esbuild.build({
// ...buildOptions,
// ...editorOption
// })
// }
break;
case "dev":
const { reload } = dev({ ...pkg.localDev.server, openBrowser: false });
const watchPlugin = {
name: "watch-plugin",
setup(build) {
console.log("watch plugin setup");
build.onStart(() => {
console.log("build starting....");
});
build.onEnd((result) => {
if (result.errors.length == 0) {
console.log("build ok");
} else {
console.log("build error");
}
});
},
};
let ctx = await esbuild.context({
...buildOptions,
// write: false,
plugins: [...buildOptions.plugins, watchPlugin],
});
await ctx.watch();
console.log("watching...");
// for (let editorOption of editorOptions) {
// esbuild.build({
// ...buildOptions,
// ...editorOption,
// ...devOptions
// })
// }
break;
}