@bddjr/vite-plugin-singlefile 3.0.2 → 3.0.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/dist/index.js +9 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -91,20 +91,17 @@ async function generateBundle(bundle, config, options) {
|
|
|
91
91
|
linkStylesheet[0].before(e);
|
|
92
92
|
for (const e of linkStylesheet) e.remove();
|
|
93
93
|
}
|
|
94
|
-
const assetsDataURL = {};
|
|
95
94
|
if (options.tryInlineHtmlAssets) for (const element of document.querySelectorAll(assetsSrcSelector)) {
|
|
96
95
|
const name = cutPrefix(element.src, assetsDirWithBase);
|
|
97
96
|
if (/\.js$/i.test(name)) continue;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
element.src = dataURL;
|
|
107
|
-
}
|
|
97
|
+
const bundleName = assetsDir + name;
|
|
98
|
+
const a = bundle[bundleName];
|
|
99
|
+
if (!a) continue;
|
|
100
|
+
thisDel.add(bundleName);
|
|
101
|
+
let dataURL;
|
|
102
|
+
if (Object.prototype.hasOwnProperty.call(globalAssetsDataURL, name)) dataURL = globalAssetsDataURL[name];
|
|
103
|
+
else globalAssetsDataURL[name] = dataURL = bufferToDataURL(name, Buffer.from(a.source));
|
|
104
|
+
element.src = dataURL;
|
|
108
105
|
}
|
|
109
106
|
if (options.tryInlineHtmlPublicIcon) {
|
|
110
107
|
let needInline = true;
|
|
@@ -145,10 +142,7 @@ async function generateBundle(bundle, config, options) {
|
|
|
145
142
|
code = code.replace(/;?\n?$/, "");
|
|
146
143
|
for (const name of bundleAssetsNames) {
|
|
147
144
|
const assetName = name.slice(assetsDir.length);
|
|
148
|
-
if (code.includes(assetName))
|
|
149
|
-
globalDoNotDelete.add(name);
|
|
150
|
-
delete assetsDataURL[assetName];
|
|
151
|
-
}
|
|
145
|
+
if (code.includes(assetName)) globalDoNotDelete.add(name);
|
|
152
146
|
}
|
|
153
147
|
let outputScript = code.replaceAll("<\/script", "<\\/script");
|
|
154
148
|
if (/\b__VITE_PRELOAD__\b/.test(code)) outputScript = "var __VITE_PRELOAD__;" + outputScript;
|