vite-plugin-inline-multipage 1.0.12 → 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.
Files changed (2) hide show
  1. package/dist/index.js +21 -7
  2. 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,20 +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
- const originalName = path.basename(htmlFile, '.html');
62
- const isRouteFile = remapKeys.has(originalName);
63
- if (isRouteFile) {
64
- const remappedName = remap[originalName];
65
- const remappedPath = path.join(path.dirname(htmlFile), remappedName);
66
- fs.writeFileSync(remappedPath, $.html());
67
- if (remappedPath !== htmlFile) {
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) {
68
81
  fs.unlinkSync(htmlFile);
69
82
  }
70
83
  }
71
84
  else {
85
+ // No remap - write original file
72
86
  fs.writeFileSync(htmlFile, $.html());
73
87
  }
74
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-inline-multipage",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "A Vite plugin that inlines multi-paged applications (like in svelte) to multiple html files",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",