@webmate-studio/builder 0.2.124 → 0.2.126

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/bundler.js +18 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmate-studio/builder",
3
- "version": "0.2.124",
3
+ "version": "0.2.126",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
package/src/bundler.js CHANGED
@@ -25,7 +25,8 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
25
25
  sourcemap = true,
26
26
  target = 'es2020',
27
27
  format = 'esm',
28
- componentDir = null // NEW: Component directory for component-specific node_modules
28
+ componentDir = null, // Component directory for component-specific node_modules
29
+ svelteCustomElement = true // Set false for mount()-based islands (preview mode)
29
30
  } = options;
30
31
 
31
32
  try {
@@ -53,6 +54,7 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
53
54
  target,
54
55
  outfile: outputPath,
55
56
  platform: 'browser',
57
+ ...(format === 'iife' ? { globalName: '__IslandExport' } : {}),
56
58
  charset: 'utf8', // Force UTF-8 output to prevent base64 corruption (esbuild bug #1501)
57
59
  // Loaders for different file types
58
60
  // NOTE: All image formats are handled by custom plugin above (image-base64-dataurl)
@@ -152,12 +154,12 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
152
154
  });
153
155
  }
154
156
  },
155
- // Svelte support (Svelte 5 Web Components)
157
+ // Svelte support
156
158
  esbuildSvelte({
157
159
  compilerOptions: {
158
- customElement: true, // Compile to Web Components
159
- css: 'injected', // CSS always injected for custom elements
160
- runes: true // Enable Svelte 5 runes ($props, $derived, $effect, etc.)
160
+ customElement: svelteCustomElement,
161
+ css: 'injected',
162
+ runes: true
161
163
  }
162
164
  })
163
165
  ],
@@ -191,7 +193,7 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
191
193
  /**
192
194
  * Bundle all islands in a component directory
193
195
  */
194
- export async function bundleComponentIslands(componentDir, outputDir) {
196
+ export async function bundleComponentIslands(componentDir, outputDir, options = {}) {
195
197
  const islandsDir = path.join(componentDir, 'islands');
196
198
 
197
199
  // Check if islands directory exists
@@ -204,7 +206,7 @@ export async function bundleComponentIslands(componentDir, outputDir) {
204
206
 
205
207
  // Find all island files (JS, JSX, Svelte, Vue, etc.)
206
208
  const files = await fs.readdir(islandsDir);
207
- const islandFiles = files.filter((f) =>
209
+ const allIslandFiles = files.filter((f) =>
208
210
  f.endsWith('.js') ||
209
211
  f.endsWith('.jsx') ||
210
212
  f.endsWith('.svelte') ||
@@ -213,6 +215,13 @@ export async function bundleComponentIslands(componentDir, outputDir) {
213
215
  f.endsWith('.tsx')
214
216
  );
215
217
 
218
+ // Skip .svelte files that have a matching .js wrapper (the .js is the entry point)
219
+ const jsNames = new Set(allIslandFiles.filter(f => f.endsWith('.js')).map(f => f.replace(/\.js$/, '')));
220
+ const islandFiles = allIslandFiles.filter(f => {
221
+ if (f.endsWith('.svelte') && jsNames.has(f.replace(/\.svelte$/, ''))) return false;
222
+ return true;
223
+ });
224
+
216
225
  if (islandFiles.length === 0) {
217
226
  return { islands: [], success: true };
218
227
  }
@@ -230,8 +239,8 @@ export async function bundleComponentIslands(componentDir, outputDir) {
230
239
 
231
240
  console.log(pc.dim(` Bundling ${islandFile}...`));
232
241
 
233
- // Pass componentDir to bundler for component-specific node_modules resolution
234
- const result = await bundleIsland(inputPath, outputPath, { componentDir });
242
+ // Pass componentDir and any extra options to bundler
243
+ const result = await bundleIsland(inputPath, outputPath, { componentDir, ...options });
235
244
 
236
245
  if (result.success) {
237
246
  const sizeKb = (result.size / 1024).toFixed(2);