vite-plugin-inline-multipage 1.0.13 → 1.0.14
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 +21 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export default function inlineEverythingPlugin(options) {
|
|
|
25
25
|
for (const htmlFile of htmlFiles) {
|
|
26
26
|
let html = fs.readFileSync(htmlFile, 'utf8');
|
|
27
27
|
const $ = cheerio.load(html);
|
|
28
|
+
// Inline CSS
|
|
28
29
|
$('link[rel="stylesheet"]').each((_, el) => {
|
|
29
30
|
const href = $(el).attr('href');
|
|
30
31
|
if (href) {
|
|
@@ -40,6 +41,7 @@ export default function inlineEverythingPlugin(options) {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
});
|
|
44
|
+
// Inline JS
|
|
43
45
|
$('script[type="module"][src]').each((_, el) => {
|
|
44
46
|
const src = $(el).attr('src');
|
|
45
47
|
if (src) {
|
|
@@ -55,22 +57,32 @@ export default function inlineEverythingPlugin(options) {
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
});
|
|
60
|
+
// Remove preload and hydration scripts
|
|
58
61
|
$('link[rel="modulepreload"]').remove();
|
|
59
62
|
$('link[rel="preload"]').remove();
|
|
60
63
|
$('script[data-sveltekit-hydrate]').remove();
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
// Determine remap key based on folder or filename
|
|
65
|
+
const filename = path.basename(htmlFile);
|
|
66
|
+
let remapKey;
|
|
67
|
+
if (filename === 'index.html') {
|
|
68
|
+
// Use the relative folder path as the key for remap
|
|
69
|
+
remapKey = path.relative(resolvedBuildDir, path.dirname(htmlFile)).replace(/\\/g, '/'); // normalize slashes
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Use the basename without extension as key
|
|
73
|
+
remapKey = path.basename(htmlFile, '.html');
|
|
74
|
+
}
|
|
75
|
+
if (remapKeys.has(remapKey)) {
|
|
76
|
+
const remappedName = remap[remapKey];
|
|
77
|
+
const newPath = path.join(path.dirname(htmlFile), remappedName);
|
|
78
|
+
fs.writeFileSync(newPath, $.html());
|
|
79
|
+
// Remove old file if different path
|
|
80
|
+
if (newPath !== htmlFile) {
|
|
70
81
|
fs.unlinkSync(htmlFile);
|
|
71
82
|
}
|
|
72
83
|
}
|
|
73
84
|
else {
|
|
85
|
+
// No remap - write original file
|
|
74
86
|
fs.writeFileSync(htmlFile, $.html());
|
|
75
87
|
}
|
|
76
88
|
}
|
package/package.json
CHANGED