@webmate-studio/builder 0.1.2 → 0.1.3
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.
- package/package.json +1 -1
- package/src/bundler.js +27 -3
package/package.json
CHANGED
package/src/bundler.js
CHANGED
|
@@ -3,6 +3,9 @@ import esbuildSvelte from 'esbuild-svelte';
|
|
|
3
3
|
import fs from 'fs/promises';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import pc from 'picocolors';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Bundle island JavaScript files with esbuild
|
|
@@ -18,12 +21,26 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
|
|
|
18
21
|
|
|
19
22
|
try {
|
|
20
23
|
// Resolve paths for dependencies from builder package
|
|
24
|
+
// In npx environment, we need to find where the actual dependencies are installed
|
|
21
25
|
const builderNodeModules = path.resolve(import.meta.dirname, '../node_modules');
|
|
22
26
|
|
|
27
|
+
// Also try to resolve from the process working directory (where components are)
|
|
28
|
+
const cwd = process.cwd();
|
|
29
|
+
const workspaceNodeModules = path.join(cwd, 'node_modules');
|
|
30
|
+
|
|
23
31
|
// Determine if this file should use JSX loader
|
|
24
32
|
// Only use JSX for .jsx files (React/Preact), not for .js files (Lit/Alpine/Vue/Vanilla)
|
|
25
33
|
const useJsxLoader = islandPath.endsWith('.jsx');
|
|
26
34
|
|
|
35
|
+
// Try to resolve Svelte package path
|
|
36
|
+
let sveltePackagePath;
|
|
37
|
+
try {
|
|
38
|
+
sveltePackagePath = path.dirname(require.resolve('svelte/package.json'));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
// Svelte not found in builder's node_modules, might be in workspace
|
|
41
|
+
sveltePackagePath = null;
|
|
42
|
+
}
|
|
43
|
+
|
|
27
44
|
const result = await esbuild.build({
|
|
28
45
|
entryPoints: [islandPath],
|
|
29
46
|
bundle: true,
|
|
@@ -47,7 +64,12 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
|
|
|
47
64
|
// JSX import source (Preact uses preact, React uses react)
|
|
48
65
|
jsxImportSource: useJsxLoader ? 'preact' : undefined,
|
|
49
66
|
// Alias vue to the full build (with template compiler)
|
|
50
|
-
alias
|
|
67
|
+
// Also alias Svelte internal modules if we found the package
|
|
68
|
+
alias: sveltePackagePath ? {
|
|
69
|
+
'vue': 'vue/dist/vue.esm-bundler.js',
|
|
70
|
+
'svelte': path.join(sveltePackagePath, 'src/runtime/index.js'),
|
|
71
|
+
'svelte/internal': path.join(sveltePackagePath, 'src/runtime/internal/index.js')
|
|
72
|
+
} : {
|
|
51
73
|
'vue': 'vue/dist/vue.esm-bundler.js'
|
|
52
74
|
},
|
|
53
75
|
// Define Vue feature flags
|
|
@@ -66,8 +88,10 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
|
|
|
66
88
|
],
|
|
67
89
|
// Don't bundle browser globals
|
|
68
90
|
external: [],
|
|
69
|
-
// Add
|
|
70
|
-
nodePaths: [builderNodeModules],
|
|
91
|
+
// Add multiple resolution paths - try both builder's node_modules and workspace node_modules
|
|
92
|
+
nodePaths: [builderNodeModules, workspaceNodeModules],
|
|
93
|
+
// Enable package.json conditions for proper Svelte module resolution
|
|
94
|
+
conditions: ['svelte', 'browser', 'import'],
|
|
71
95
|
// Log level
|
|
72
96
|
logLevel: 'warning'
|
|
73
97
|
});
|