-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
115 lines (103 loc) · 3.09 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
// const esbuild = require("esbuild");
// const watchMode = process.argv.includes("--watch");
// const options = {
// entryPoints: ["app/javascript/wilday_ui/index.js"],
// bundle: true,
// outdir: "app/assets/builds/wilday_ui",
// format: "esm",
// globalName: "WildayUi",
// sourcemap: process.env.NODE_ENV === "development",
// minify: process.env.NODE_ENV === "production",
// logLevel: "info",
// external: ["@hotwired/stimulus"],
// loader: {
// ".js": "jsx",
// },
// };
// // Stimulus setup by ensuring all controllers are loaded
// const controllers = require("path").resolve(
// "app/javascript/wilday_ui/controllers"
// );
// // Check if running in watch mode
// // if (process.env.NODE_ENV === "development") {
// if (watchMode) {
// esbuild
// .context(options)
// .then((ctx) => {
// // Log Stimulus controller loading for debugging
// console.log(`Loading Stimulus controllers from: ${controllers}`);
// return ctx.watch();
// })
// .then(() => {
// console.log("👀 Watching for changes...");
// })
// .catch((error) => {
// console.error("Error during build:", error);
// process.exit(1);
// });
// } else {
// // Build in production mode
// esbuild
// .build(options)
// .then(() => {
// console.log(
// `Successfully bundled Stimulus controllers from: ${controllers}`
// );
// })
// .catch((error) => {
// console.error("Error during build:", error);
// process.exit(1);
// });
// }
const esbuild = require("esbuild");
const path = require("path");
// Check for watch mode from command line args
const watchMode = process.argv.includes("--watch");
// Define paths
const controllersPath = path.resolve("app/javascript/wilday_ui/controllers");
const entryPoint = "app/javascript/wilday_ui/index.js";
const outputDir = "app/assets/builds/wilday_ui";
// Base build options
const options = {
entryPoints: [entryPoint],
bundle: true,
outdir: outputDir,
format: "esm",
globalName: "WildayUi",
sourcemap: process.env.NODE_ENV === "development",
minify: process.env.NODE_ENV === "production",
logLevel: "info",
loader: {
".js": "jsx",
},
};
// Build function
async function build() {
try {
console.log("🎯 Wilday UI: Starting build process...");
console.log(`📁 Loading controllers from: ${controllersPath}`);
if (watchMode) {
// Watch mode
console.log("👀 Watching for changes...");
console.log(` Entry: ${entryPoint}`);
console.log(` Output: ${outputDir}`);
console.log(` Mode: ${process.env.NODE_ENV}`);
const context = await esbuild.context(options);
await context.watch();
} else {
// Production build
console.log("🏗 Building for production...");
const result = await esbuild.build(options);
console.log("✅ Build completed successfully");
}
} catch (err) {
console.error("❌ Build failed:", err);
process.exit(1);
}
}
// Execute build
build().then(() => {
if (!watchMode) {
console.log("🎉 Wilday UI: Build process completed");
}
});