From 01557b9dca31521c2fd1e5d2fdfb7854e915daf2 Mon Sep 17 00:00:00 2001 From: Maija Lintunokka Date: Thu, 11 Dec 2025 14:53:38 +0200 Subject: [PATCH 1/2] feat: add support for preview dev server --- esbuild.mjs | 19 ++++++++++++++----- package.json | 1 + src/main.ts | 1 + vite.config.ts | 5 +++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/esbuild.mjs b/esbuild.mjs index 304cf5d5..4d8840f4 100644 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -14,19 +14,19 @@ const sharedConfig = { async function build() { try { - await esbuild.build({ + const ctx1 = await esbuild.context({ ...sharedConfig, outfile: "dist/main.cjs.js", format: "cjs" }) - await esbuild.build({ + const ctx2 = await esbuild.context({ ...sharedConfig, outfile: "dist/main.es.js", format: "esm" }) - const result = await esbuild.build({ + const ctx3 = await esbuild.context({ ...sharedConfig, minifyWhitespace: true, outfile: "dist/main.es.bundle.js", @@ -34,9 +34,18 @@ async function build() { metafile: true }) - fs.writeFileSync("meta.json", JSON.stringify(result.metafile)) + if (process.argv.includes("--watch")) { + await Promise.all([ctx1.watch(), ctx2.watch(), ctx3.watch()]) + console.info("Watching for changes...") + } else { + const results = await Promise.all([ctx1.rebuild(), ctx2.rebuild(), ctx3.rebuild()]) + fs.writeFileSync("meta.json", JSON.stringify(results[2].metafile)) - console.log("Build completed successfully.") + ctx1.dispose() + ctx2.dispose() + ctx3.dispose() + console.info("Build completed successfully.") + } } catch (error) { console.error("Build failed:", error) process.exit(1) diff --git a/package.json b/package.json index ff9f90f7..e261715b 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "scripts": { "build": "tsc --project tsconfig.types.json && node esbuild.mjs && npm run typedoc", + "dev": "node esbuild.mjs --watch & vite preview --outDir dist", "preview": "vite preview", "lint": "eslint", "lint-fix": "eslint --fix", diff --git a/src/main.ts b/src/main.ts index c5a0f2a8..c01b4f28 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ export { Bundle } from "./components/Bundle/Bundle" export { Campaign } from "./components/Campaign/Campaign" export { Control } from "./components/Control/Control" export { DynamicCard, setDynamicCardDefaults } from "./components/DynamicCard/DynamicCard" +export { DynamicCardList } from "./components/DynamicCardList/DynamicCardList" export { Image } from "./components/Image/Image" export { Product } from "./components/Product/Product" export { SectionCampaign } from "./components/SectionCampaign/SectionCampaign" diff --git a/vite.config.ts b/vite.config.ts index 74ac61f9..1b7253f4 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,6 +10,11 @@ export default defineConfig(() => ({ server: { port: 8080 }, + preview: { + port: 40510, + open: false, + cors: true + }, test: { coverage: { include: ["src/**/*.{js,ts}"], From 50e8fee9756c77443a540eb59a55896563695a06 Mon Sep 17 00:00:00 2001 From: Maija Lintunokka Date: Thu, 11 Dec 2025 16:08:22 +0200 Subject: [PATCH 2/2] fix: remove wrong import --- src/main.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index c01b4f28..c5a0f2a8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,6 @@ export { Bundle } from "./components/Bundle/Bundle" export { Campaign } from "./components/Campaign/Campaign" export { Control } from "./components/Control/Control" export { DynamicCard, setDynamicCardDefaults } from "./components/DynamicCard/DynamicCard" -export { DynamicCardList } from "./components/DynamicCardList/DynamicCardList" export { Image } from "./components/Image/Image" export { Product } from "./components/Product/Product" export { SectionCampaign } from "./components/SectionCampaign/SectionCampaign"