@webmate-studio/builder 0.2.13 → 0.2.15
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 +38 -17
package/package.json
CHANGED
package/src/bundler.js
CHANGED
|
@@ -43,28 +43,17 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
|
|
|
43
43
|
outfile: outputPath,
|
|
44
44
|
platform: 'browser',
|
|
45
45
|
// Loaders for different file types
|
|
46
|
-
// NOTE:
|
|
47
|
-
//
|
|
48
|
-
// but works with base64 (data:image/svg+xml;base64,PHN2Zy4uLg==)
|
|
46
|
+
// NOTE: All image formats are handled by custom plugin above (image-base64-dataurl)
|
|
47
|
+
// to generate proper data:image/...;base64,... URLs for CSS compatibility
|
|
49
48
|
loader: useJsxLoader ? {
|
|
50
49
|
'.jsx': 'jsx',
|
|
51
50
|
'.ts': 'tsx',
|
|
52
|
-
'.tsx': 'tsx'
|
|
53
|
-
|
|
54
|
-
'.jpeg': 'dataurl',
|
|
55
|
-
'.png': 'dataurl',
|
|
56
|
-
'.gif': 'dataurl',
|
|
57
|
-
'.svg': 'base64', // Changed from 'dataurl' to 'base64' for CSS compatibility
|
|
58
|
-
'.webp': 'dataurl'
|
|
51
|
+
'.tsx': 'tsx'
|
|
52
|
+
// All image formats (.svg, .jpg, .png, etc.) handled by custom plugin
|
|
59
53
|
} : {
|
|
60
54
|
'.ts': 'tsx',
|
|
61
|
-
'.tsx': 'tsx'
|
|
62
|
-
|
|
63
|
-
'.jpeg': 'dataurl',
|
|
64
|
-
'.png': 'dataurl',
|
|
65
|
-
'.gif': 'dataurl',
|
|
66
|
-
'.svg': 'base64', // Changed from 'dataurl' to 'base64' for CSS compatibility
|
|
67
|
-
'.webp': 'dataurl'
|
|
55
|
+
'.tsx': 'tsx'
|
|
56
|
+
// All image formats (.svg, .jpg, .png, etc.) handled by custom plugin
|
|
68
57
|
},
|
|
69
58
|
// Use automatic JSX runtime (React 17+) only for JSX files
|
|
70
59
|
jsx: useJsxLoader ? 'automatic' : undefined,
|
|
@@ -81,6 +70,38 @@ export async function bundleIsland(islandPath, outputPath, options = {}) {
|
|
|
81
70
|
'__VUE_PROD_HYDRATION_MISMATCH_DETAILS__': 'false'
|
|
82
71
|
},
|
|
83
72
|
plugins: [
|
|
73
|
+
// Image to base64 data URL loader
|
|
74
|
+
// esbuild's 'dataurl' loader fails for:
|
|
75
|
+
// - SVG: generates invalid data:image/svg+xml,<?xml... (unescaped XML)
|
|
76
|
+
// - JPG/PNG/etc: generates invalid data:image/jpeg,���� (raw binary instead of base64)
|
|
77
|
+
// Solution: Custom loader that properly base64 encodes ALL image formats
|
|
78
|
+
{
|
|
79
|
+
name: 'image-base64-dataurl',
|
|
80
|
+
setup(build) {
|
|
81
|
+
// Handle all image formats
|
|
82
|
+
build.onLoad({ filter: /\.(svg|jpg|jpeg|png|gif|webp)$/i }, async (args) => {
|
|
83
|
+
const ext = args.path.split('.').pop().toLowerCase();
|
|
84
|
+
const mimeTypes = {
|
|
85
|
+
svg: 'image/svg+xml',
|
|
86
|
+
jpg: 'image/jpeg',
|
|
87
|
+
jpeg: 'image/jpeg',
|
|
88
|
+
png: 'image/png',
|
|
89
|
+
gif: 'image/gif',
|
|
90
|
+
webp: 'image/webp'
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const content = await fs.readFile(args.path);
|
|
94
|
+
const base64 = content.toString('base64');
|
|
95
|
+
const mimeType = mimeTypes[ext] || 'application/octet-stream';
|
|
96
|
+
const dataUrl = `data:${mimeType};base64,${base64}`;
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
contents: `export default ${JSON.stringify(dataUrl)}`,
|
|
100
|
+
loader: 'js'
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
84
105
|
// CSS imports from node_modules (e.g., import "swiper/swiper-bundle.css")
|
|
85
106
|
// Convert to inline text that can be injected as <style> tag
|
|
86
107
|
{
|