forked from Matdata-eu/Yasgui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathesbuild.config.js
More file actions
144 lines (126 loc) · 3.82 KB
/
esbuild.config.js
File metadata and controls
144 lines (126 loc) · 3.82 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import * as esbuild from "esbuild";
import { sassPlugin } from "esbuild-sass-plugin";
import * as fs from "fs";
import * as path from "path";
import postcss from "postcss";
import autoprefixer from "autoprefixer";
import { execSync } from "child_process";
const isProd = process.env.NODE_ENV === "production";
// Clean build directory
if (fs.existsSync("./build")) {
fs.rmSync("./build", { recursive: true, force: true });
}
// Create build directory
fs.mkdirSync("./build", { recursive: true });
// Copy static files
function copyDir(src, dest) {
if (!fs.existsSync(src)) return;
fs.mkdirSync(dest, { recursive: true });
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
// Copy static assets
copyDir("packages/yasgui/static", "build/packages/yasgui/static");
// Copy HTML files for testing (from build-templates, not dev)
const htmlFiles = ["index.html", "yasgui.html", "yasqe.html", "yasr.html"];
for (const file of htmlFiles) {
const src = path.join("build-templates", file);
const dest = path.join("build", file);
if (fs.existsSync(src)) {
fs.copyFileSync(src, dest);
}
}
const commonConfig = {
bundle: true,
sourcemap: true,
target: "es2020",
minify: isProd,
plugins: [
sassPlugin({
async transform(source, resolveDir) {
const { css } = await postcss([autoprefixer]).process(source, { from: undefined });
return css;
},
}),
],
loader: {
".png": "file",
".jpg": "file",
".svg": "dataurl",
".woff": "file",
".woff2": "file",
".ttf": "file",
".eot": "file",
},
external: [],
define: {
__DEVELOPMENT__: JSON.stringify(!isProd),
},
};
async function buildPackage(name, entryPoint, globalName) {
const result = await esbuild.build({
...commonConfig,
entryPoints: [entryPoint],
outfile: `build/${name}.min.js`,
format: "iife",
globalName: globalName,
platform: "browser",
metafile: true,
footer: {
// Unwrap default export for IIFE format to make constructor available as global
js: `if (typeof ${globalName} !== 'undefined' && ${globalName}?.default) { ${globalName} = ${globalName}.default; }`,
},
});
// Extract CSS if any was bundled
if (result.metafile) {
const outputs = Object.keys(result.metafile.outputs);
const cssOutput = outputs.find((o) => o.endsWith(".css"));
if (cssOutput && fs.existsSync(cssOutput)) {
fs.renameSync(cssOutput, `build/${name}.min.css`);
}
}
}
async function buildTypeDeclarations() {
console.log("Building TypeScript declarations...");
try {
execSync("tsc -p tsconfig-build.json", { stdio: "inherit" });
} catch (error) {
console.warn("TypeScript declaration build had errors, continuing...");
}
}
async function updateVersion() {
console.log("Updating version.ts...");
try {
execSync("node updateVersion.js", { stdio: "inherit" });
} catch (error) {
console.warn("Failed to update version.ts, continuing...");
}
}
async function build() {
try {
// Update version.ts from package.json
await updateVersion();
// Build TypeScript declarations first
await buildTypeDeclarations();
// Build all packages
await Promise.all([
buildPackage("yasgui", "packages/yasgui/src/index.ts", "Yasgui"),
buildPackage("yasqe", "packages/yasqe/src/index.ts", "Yasqe"),
buildPackage("yasr", "packages/yasr/src/index.ts", "Yasr"),
buildPackage("utils", "packages/utils/src/index.ts", "Utils"),
]);
console.log("✓ Build complete!");
} catch (error) {
console.error("Build failed:", error);
process.exit(1);
}
}
build();