vite-plugin-smart-prefetch 0.3.1 → 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 +44 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -21
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +13 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +13 -1
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/index.cjs +13 -1
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +13 -1
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -698,21 +698,14 @@ var _ConfigGenerator = class _ConfigGenerator {
|
|
|
698
698
|
}
|
|
699
699
|
prediction.prefetch.forEach((target) => {
|
|
700
700
|
const chunkFile = this.routeToChunk(target.route);
|
|
701
|
+
let imports = [];
|
|
701
702
|
if (chunkFile) {
|
|
702
703
|
const manifestEntry = this.getManifestEntryByFile(chunkFile);
|
|
703
704
|
const importChunkIds = manifestEntry?.imports || [];
|
|
704
|
-
|
|
705
|
+
imports = importChunkIds.map((chunkId) => {
|
|
705
706
|
const entry = this.manifest[chunkId];
|
|
706
707
|
return entry?.file;
|
|
707
708
|
}).filter((file) => !!file);
|
|
708
|
-
prefetchTargets.push({
|
|
709
|
-
...target,
|
|
710
|
-
chunk: chunkFile,
|
|
711
|
-
chunk_prod: chunkFile,
|
|
712
|
-
// NEW: Include production chunk path
|
|
713
|
-
imports
|
|
714
|
-
// Include dependency chunks (resolved to file paths)
|
|
715
|
-
});
|
|
716
709
|
config.chunks[target.route] = chunkFile;
|
|
717
710
|
mappedRoutes++;
|
|
718
711
|
if (this.debug) {
|
|
@@ -729,29 +722,39 @@ var _ConfigGenerator = class _ConfigGenerator {
|
|
|
729
722
|
}
|
|
730
723
|
unmappedRoutes++;
|
|
731
724
|
}
|
|
725
|
+
prefetchTargets.push({
|
|
726
|
+
...target,
|
|
727
|
+
chunk: chunkFile || void 0,
|
|
728
|
+
// Include chunk (may be undefined)
|
|
729
|
+
chunk_prod: chunkFile || void 0,
|
|
730
|
+
// Include production chunk path
|
|
731
|
+
imports
|
|
732
|
+
});
|
|
732
733
|
});
|
|
733
734
|
if (prediction.segments) {
|
|
734
735
|
Object.entries(prediction.segments).forEach(([segment, segmentTargets]) => {
|
|
735
736
|
const segmentPrefetchTargets = [];
|
|
736
737
|
segmentTargets.forEach((target) => {
|
|
737
738
|
const chunkFile = this.routeToChunk(target.route);
|
|
739
|
+
let imports = [];
|
|
738
740
|
if (chunkFile) {
|
|
739
741
|
const manifestEntry = this.getManifestEntryByFile(chunkFile);
|
|
740
742
|
const importChunkIds = manifestEntry?.imports || [];
|
|
741
|
-
|
|
743
|
+
imports = importChunkIds.map((chunkId) => {
|
|
742
744
|
const entry = this.manifest[chunkId];
|
|
743
745
|
return entry?.file;
|
|
744
746
|
}).filter((file) => !!file);
|
|
745
|
-
segmentPrefetchTargets.push({
|
|
746
|
-
...target,
|
|
747
|
-
chunk: chunkFile,
|
|
748
|
-
chunk_prod: chunkFile,
|
|
749
|
-
// NEW: Include production chunk path
|
|
750
|
-
imports
|
|
751
|
-
});
|
|
752
747
|
config.chunks[target.route] = chunkFile;
|
|
753
748
|
totalSegmentRules++;
|
|
754
749
|
}
|
|
750
|
+
segmentPrefetchTargets.push({
|
|
751
|
+
...target,
|
|
752
|
+
chunk: chunkFile || void 0,
|
|
753
|
+
// Include chunk (may be undefined)
|
|
754
|
+
chunk_prod: chunkFile || void 0,
|
|
755
|
+
// Include production chunk path
|
|
756
|
+
imports
|
|
757
|
+
});
|
|
755
758
|
});
|
|
756
759
|
if (segmentPrefetchTargets.length > 0) {
|
|
757
760
|
segmentConfigs[segment] = segmentPrefetchTargets;
|
|
@@ -1170,9 +1173,23 @@ var _ConfigGenerator = class _ConfigGenerator {
|
|
|
1170
1173
|
};
|
|
1171
1174
|
/**
|
|
1172
1175
|
* Maps routes to their component names based on vite.config.ts chunk strategy
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
+
*
|
|
1177
|
+
* ⚠️ HARDCODED MAPPINGS ARE NOT RECOMMENDED FOR PRODUCTION
|
|
1178
|
+
*
|
|
1179
|
+
* These mappings should NOT be hardcoded in the plugin.
|
|
1180
|
+
* Instead, implement one of these approaches:
|
|
1181
|
+
*
|
|
1182
|
+
* 1. **Extract from Vite Config (RECOMMENDED)**:
|
|
1183
|
+
* Pass route-to-chunk mappings from your vite.config.ts manualChunks strategy
|
|
1184
|
+
* This keeps mappings DRY and maintainable.
|
|
1185
|
+
*
|
|
1186
|
+
* 2. **Generate from Route Files**:
|
|
1187
|
+
* Scan your routes/pages directory to dynamically build mappings
|
|
1188
|
+
*
|
|
1189
|
+
* 3. **Use Route Metadata**:
|
|
1190
|
+
* Add metadata to route definitions specifying their chunk names
|
|
1191
|
+
*
|
|
1192
|
+
* Current hardcoded mappings (will be removed in v0.4.0):
|
|
1176
1193
|
*/
|
|
1177
1194
|
_ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
|
|
1178
1195
|
"/": "Home",
|
|
@@ -1208,10 +1225,16 @@ _ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
|
|
|
1208
1225
|
};
|
|
1209
1226
|
/**
|
|
1210
1227
|
* Maps component names to chunk names based on vite.config.ts manualChunks strategy
|
|
1211
|
-
*
|
|
1228
|
+
*
|
|
1229
|
+
* ⚠️ HARDCODED MAPPINGS ARE NOT RECOMMENDED FOR PRODUCTION
|
|
1230
|
+
*
|
|
1231
|
+
* Each component is assigned to a specific chunk group for code splitting.
|
|
1232
|
+
* These mappings should be extracted from your actual vite.config.ts, not hardcoded.
|
|
1212
1233
|
*
|
|
1213
1234
|
* Note: Core components (Home, Dashboard) are not in manual chunks - they're part of main bundle
|
|
1214
1235
|
* For these, we return the main bundle file path 'js/index-*.js' which will be resolved from manifest
|
|
1236
|
+
*
|
|
1237
|
+
* Will be removed in v0.4.0. Use plugin config to pass mappings instead.
|
|
1215
1238
|
*/
|
|
1216
1239
|
_ConfigGenerator.COMPONENT_TO_CHUNK_NAME = {
|
|
1217
1240
|
// Core components - loaded with main bundle (not code-split)
|