vite-plugin-inline-multipage 1.0.13 → 1.0.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/dist/index.js +18 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ import fs from 'fs';
|
|
|
4
4
|
import * as cheerio from 'cheerio';
|
|
5
5
|
export default function inlineEverythingPlugin(options) {
|
|
6
6
|
const { buildDir = 'build', cleanUp = false, remap = {}, } = options || {};
|
|
7
|
-
const remapKeys = new Set(Object.keys(remap));
|
|
8
7
|
return {
|
|
9
8
|
name: 'inline-everything',
|
|
10
9
|
apply: 'build',
|
|
@@ -58,21 +57,26 @@ export default function inlineEverythingPlugin(options) {
|
|
|
58
57
|
$('link[rel="modulepreload"]').remove();
|
|
59
58
|
$('link[rel="preload"]').remove();
|
|
60
59
|
$('script[data-sveltekit-hydrate]').remove();
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (
|
|
70
|
-
|
|
60
|
+
// Determine relative path and parts
|
|
61
|
+
const relativePath = path.relative(resolvedBuildDir, htmlFile);
|
|
62
|
+
const pathParts = relativePath.split(path.sep);
|
|
63
|
+
const originalName = path.basename(htmlFile, '.html');
|
|
64
|
+
// Apply remap ONLY for index.html inside one-level subfolders (routes)
|
|
65
|
+
const isIndexInSubfolder = pathParts.length === 2 && originalName === 'index';
|
|
66
|
+
if (isIndexInSubfolder) {
|
|
67
|
+
const routeName = pathParts[0]; // e.g. 'main'
|
|
68
|
+
if (remap.hasOwnProperty(routeName)) {
|
|
69
|
+
const remappedName = remap[routeName];
|
|
70
|
+
const remappedPath = path.join(path.dirname(htmlFile), remappedName);
|
|
71
|
+
fs.writeFileSync(remappedPath, $.html());
|
|
72
|
+
if (remappedPath !== htmlFile) {
|
|
73
|
+
fs.unlinkSync(htmlFile);
|
|
74
|
+
}
|
|
75
|
+
continue; // skip writing original file below
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
78
|
+
// Write processed html back for all other files
|
|
79
|
+
fs.writeFileSync(htmlFile, $.html());
|
|
76
80
|
}
|
|
77
81
|
if (cleanUp) {
|
|
78
82
|
try {
|
package/package.json
CHANGED