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.
Files changed (2) hide show
  1. package/dist/index.js +18 -14
  2. 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
- const relPath = path.relative(resolvedBuildDir, htmlFile);
62
- const match = relPath.match(/^(.*?)\/index\.html$/);
63
- const routeKey = match ? match[1] : path.basename(htmlFile, '.html');
64
- const isRouteFile = remapKeys.has(routeKey);
65
- if (isRouteFile) {
66
- const remappedName = remap[routeKey];
67
- const remappedPath = path.join(path.dirname(htmlFile), remappedName);
68
- fs.writeFileSync(remappedPath, $.html());
69
- if (remappedPath !== htmlFile) {
70
- fs.unlinkSync(htmlFile);
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
- else {
74
- fs.writeFileSync(htmlFile, $.html());
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-inline-multipage",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
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",