vite-plugin-smart-prefetch 0.3.2 → 0.3.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.cjs CHANGED
@@ -734,21 +734,14 @@ var _ConfigGenerator = class _ConfigGenerator {
734
734
  }
735
735
  prediction.prefetch.forEach((target) => {
736
736
  const chunkFile = this.routeToChunk(target.route);
737
+ let imports = [];
737
738
  if (chunkFile) {
738
739
  const manifestEntry = this.getManifestEntryByFile(chunkFile);
739
740
  const importChunkIds = manifestEntry?.imports || [];
740
- const imports = importChunkIds.map((chunkId) => {
741
+ imports = importChunkIds.map((chunkId) => {
741
742
  const entry = this.manifest[chunkId];
742
743
  return entry?.file;
743
744
  }).filter((file) => !!file);
744
- prefetchTargets.push({
745
- ...target,
746
- chunk: chunkFile,
747
- chunk_prod: chunkFile,
748
- // NEW: Include production chunk path
749
- imports
750
- // Include dependency chunks (resolved to file paths)
751
- });
752
745
  config.chunks[target.route] = chunkFile;
753
746
  mappedRoutes++;
754
747
  if (this.debug) {
@@ -765,29 +758,39 @@ var _ConfigGenerator = class _ConfigGenerator {
765
758
  }
766
759
  unmappedRoutes++;
767
760
  }
761
+ prefetchTargets.push({
762
+ ...target,
763
+ chunk: chunkFile || void 0,
764
+ // Include chunk (may be undefined)
765
+ chunk_prod: chunkFile || void 0,
766
+ // Include production chunk path
767
+ imports
768
+ });
768
769
  });
769
770
  if (prediction.segments) {
770
771
  Object.entries(prediction.segments).forEach(([segment, segmentTargets]) => {
771
772
  const segmentPrefetchTargets = [];
772
773
  segmentTargets.forEach((target) => {
773
774
  const chunkFile = this.routeToChunk(target.route);
775
+ let imports = [];
774
776
  if (chunkFile) {
775
777
  const manifestEntry = this.getManifestEntryByFile(chunkFile);
776
778
  const importChunkIds = manifestEntry?.imports || [];
777
- const imports = importChunkIds.map((chunkId) => {
779
+ imports = importChunkIds.map((chunkId) => {
778
780
  const entry = this.manifest[chunkId];
779
781
  return entry?.file;
780
782
  }).filter((file) => !!file);
781
- segmentPrefetchTargets.push({
782
- ...target,
783
- chunk: chunkFile,
784
- chunk_prod: chunkFile,
785
- // NEW: Include production chunk path
786
- imports
787
- });
788
783
  config.chunks[target.route] = chunkFile;
789
784
  totalSegmentRules++;
790
785
  }
786
+ segmentPrefetchTargets.push({
787
+ ...target,
788
+ chunk: chunkFile || void 0,
789
+ // Include chunk (may be undefined)
790
+ chunk_prod: chunkFile || void 0,
791
+ // Include production chunk path
792
+ imports
793
+ });
791
794
  });
792
795
  if (segmentPrefetchTargets.length > 0) {
793
796
  segmentConfigs[segment] = segmentPrefetchTargets;
@@ -1206,9 +1209,23 @@ var _ConfigGenerator = class _ConfigGenerator {
1206
1209
  };
1207
1210
  /**
1208
1211
  * Maps routes to their component names based on vite.config.ts chunk strategy
1209
- * This is derived from the route configuration in src/routes/index.ts
1210
- * Note: These are the core routes from vite.config.ts chunking strategy
1211
- * Routes not listed here will fall through to fuzzy matching
1212
+ *
1213
+ * ⚠️ HARDCODED MAPPINGS ARE NOT RECOMMENDED FOR PRODUCTION
1214
+ *
1215
+ * These mappings should NOT be hardcoded in the plugin.
1216
+ * Instead, implement one of these approaches:
1217
+ *
1218
+ * 1. **Extract from Vite Config (RECOMMENDED)**:
1219
+ * Pass route-to-chunk mappings from your vite.config.ts manualChunks strategy
1220
+ * This keeps mappings DRY and maintainable.
1221
+ *
1222
+ * 2. **Generate from Route Files**:
1223
+ * Scan your routes/pages directory to dynamically build mappings
1224
+ *
1225
+ * 3. **Use Route Metadata**:
1226
+ * Add metadata to route definitions specifying their chunk names
1227
+ *
1228
+ * Current hardcoded mappings (will be removed in v0.4.0):
1212
1229
  */
1213
1230
  _ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
1214
1231
  "/": "Home",
@@ -1244,10 +1261,16 @@ _ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
1244
1261
  };
1245
1262
  /**
1246
1263
  * Maps component names to chunk names based on vite.config.ts manualChunks strategy
1247
- * Each component is assigned to a specific chunk group for code splitting
1264
+ *
1265
+ * ⚠️ HARDCODED MAPPINGS ARE NOT RECOMMENDED FOR PRODUCTION
1266
+ *
1267
+ * Each component is assigned to a specific chunk group for code splitting.
1268
+ * These mappings should be extracted from your actual vite.config.ts, not hardcoded.
1248
1269
  *
1249
1270
  * Note: Core components (Home, Dashboard) are not in manual chunks - they're part of main bundle
1250
1271
  * For these, we return the main bundle file path 'js/index-*.js' which will be resolved from manifest
1272
+ *
1273
+ * Will be removed in v0.4.0. Use plugin config to pass mappings instead.
1251
1274
  */
1252
1275
  _ConfigGenerator.COMPONENT_TO_CHUNK_NAME = {
1253
1276
  // Core components - loaded with main bundle (not code-split)