-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathesbuild.config.js
129 lines (116 loc) · 2.79 KB
/
esbuild.config.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
console.log("ESBuild config loaded");
const stylePlugin = require("esbuild-style-plugin");
const {clean} = require("esbuild-plugin-clean");
const {copy} = require("esbuild-plugin-copy");
const {merge} = require("webpack-merge");
const {build, context} = require("esbuild");
const {zip} = require("zip-a-folder");
const manifest = require("./uxp/manifest.json");
const chokidar = require("chokidar");
const mode = process.argv[2];
//console.log(copy);
console.log(`Mode: ${mode}`);
let isProduction = false;
switch (mode) {
case "--build":
isProduction = true;
break;
case "--watch":
break;
default:
console.error(`unknown mode: ${mode}`);
process.exit(1);
}
const config = merge(
{
entryPoints: ["./src/shared/classes/Main.ts"],
logLevel: "info",
bundle: true,
minify: false,
sourcemap: "inline",
platform: "browser",
target: ["es2022", "node18"],
external: ["photoshop", "uxp", "fs", "os"],
outfile: "./dist/index.js",
// adds less plugin
plugins: [
clean({
patterns: "./dist",
}),
copy({
assets: {
from: "./uxp/**",
to: "./",
},
watch: true,
}),
stylePlugin(),
],
footer: {
// fixes sourcemap issue
js: "//# sourceURL=webpack-internal:///./src/",
},
// Disable some features/minification to make it work in UXP
supported: {
// JavaScript
"top-level-await": false,
// CSS... because UXP is special
"hex-rgba": false,
"inline-style": false,
"inset-property": false,
"is-pseudo-class": false,
"modern-rgb-hsl": false,
"nesting": false,
"rebecca-purple": false,
},
},
isProduction && {
minify: true,
keepNames: true,
sourcemap: false,
footer: {js: ""},
legalComments: "inline",
},
);
(async () => {
try {
const start = Date.now();
if (isProduction) {
// build plugin
await build(config);
// pack plugin into installer
await zip("./dist", `./installer/${manifest.name}_${manifest.id}_v${manifest.version.replace(/\./gm, "-")}.ccx`);
} else {
// prepare watcher
let ctx = await context(config);
// add some extra files to watch for
chokidar.watch("./uxp/**",
{
// only after change happened
ignoreInitial: true,
// polling to group changes
usePolling: true,
interval: 500,
},
).on("all", async (event, path) => {
console.log(event, path);
// cancel already running build
await ctx.cancel();
// dispose old context
await ctx.dispose();
// create new context
ctx = await context(config);
// start watching again
await ctx.watch();
});
// start watching
await ctx.watch();
}
console.log("ESBuild finished: " + (Date.now() - start) + "ms");
} catch (err) {
console.error(err);
process.exit(1);
}
})();