vite-plugin-smart-prefetch 0.3.3 → 0.3.4

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
@@ -39,9 +39,10 @@ var import_bigquery = require("@google-cloud/bigquery");
39
39
  var import_fs = require("fs");
40
40
  var import_path = require("path");
41
41
  var BigQueryAnalyticsConnector = class {
42
- constructor(projectId, datasetId, debug = false) {
42
+ constructor(projectId, datasetId, location = "asia-south1", debug = false) {
43
43
  this.projectId = projectId;
44
44
  this.datasetId = datasetId;
45
+ this.location = location;
45
46
  this.debug = debug;
46
47
  this.bigquery = new import_bigquery.BigQuery({
47
48
  projectId
@@ -50,6 +51,7 @@ var BigQueryAnalyticsConnector = class {
50
51
  console.log("\u2705 BigQuery Analytics connector initialized");
51
52
  console.log(` Project ID: ${projectId}`);
52
53
  console.log(` Dataset ID: ${datasetId}`);
54
+ console.log(` Location: ${location}`);
53
55
  }
54
56
  }
55
57
  /**
@@ -108,7 +110,7 @@ var BigQueryAnalyticsConnector = class {
108
110
  }
109
111
  const [rows] = await this.bigquery.query({
110
112
  query,
111
- location: "US"
113
+ location: this.location
112
114
  });
113
115
  if (this.debug) {
114
116
  console.log(`\u2705 Query executed successfully`);
@@ -361,7 +363,7 @@ var BigQueryAnalyticsConnector = class {
361
363
  }
362
364
  const [rows] = await this.bigquery.query({
363
365
  query,
364
- location: "US"
366
+ location: this.location
365
367
  });
366
368
  if (this.debug) {
367
369
  console.log(`\u2705 Query executed successfully`);
@@ -422,7 +424,7 @@ var BigQueryAnalyticsConnector = class {
422
424
  const query = `SELECT 1 as test_value`;
423
425
  await this.bigquery.query({
424
426
  query,
425
- location: "US"
427
+ location: this.location
426
428
  });
427
429
  if (this.debug) {
428
430
  console.log("\u2705 BigQuery connection test successful");
@@ -734,14 +736,21 @@ var _ConfigGenerator = class _ConfigGenerator {
734
736
  }
735
737
  prediction.prefetch.forEach((target) => {
736
738
  const chunkFile = this.routeToChunk(target.route);
737
- let imports = [];
738
739
  if (chunkFile) {
739
740
  const manifestEntry = this.getManifestEntryByFile(chunkFile);
740
741
  const importChunkIds = manifestEntry?.imports || [];
741
- imports = importChunkIds.map((chunkId) => {
742
+ const imports = importChunkIds.map((chunkId) => {
742
743
  const entry = this.manifest[chunkId];
743
744
  return entry?.file;
744
745
  }).filter((file) => !!file);
746
+ prefetchTargets.push({
747
+ ...target,
748
+ chunk: chunkFile,
749
+ chunk_prod: chunkFile,
750
+ // NEW: Include production chunk path
751
+ imports
752
+ // Include dependency chunks (resolved to file paths)
753
+ });
745
754
  config.chunks[target.route] = chunkFile;
746
755
  mappedRoutes++;
747
756
  if (this.debug) {
@@ -758,39 +767,29 @@ var _ConfigGenerator = class _ConfigGenerator {
758
767
  }
759
768
  unmappedRoutes++;
760
769
  }
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
- });
769
770
  });
770
771
  if (prediction.segments) {
771
772
  Object.entries(prediction.segments).forEach(([segment, segmentTargets]) => {
772
773
  const segmentPrefetchTargets = [];
773
774
  segmentTargets.forEach((target) => {
774
775
  const chunkFile = this.routeToChunk(target.route);
775
- let imports = [];
776
776
  if (chunkFile) {
777
777
  const manifestEntry = this.getManifestEntryByFile(chunkFile);
778
778
  const importChunkIds = manifestEntry?.imports || [];
779
- imports = importChunkIds.map((chunkId) => {
779
+ const imports = importChunkIds.map((chunkId) => {
780
780
  const entry = this.manifest[chunkId];
781
781
  return entry?.file;
782
782
  }).filter((file) => !!file);
783
+ segmentPrefetchTargets.push({
784
+ ...target,
785
+ chunk: chunkFile,
786
+ chunk_prod: chunkFile,
787
+ // NEW: Include production chunk path
788
+ imports
789
+ });
783
790
  config.chunks[target.route] = chunkFile;
784
791
  totalSegmentRules++;
785
792
  }
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
- });
794
793
  });
795
794
  if (segmentPrefetchTargets.length > 0) {
796
795
  segmentConfigs[segment] = segmentPrefetchTargets;
@@ -1209,23 +1208,9 @@ var _ConfigGenerator = class _ConfigGenerator {
1209
1208
  };
1210
1209
  /**
1211
1210
  * Maps routes to their component names based on vite.config.ts chunk strategy
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):
1211
+ * This is derived from the route configuration in src/routes/index.ts
1212
+ * Note: These are the core routes from vite.config.ts chunking strategy
1213
+ * Routes not listed here will fall through to fuzzy matching
1229
1214
  */
1230
1215
  _ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
1231
1216
  "/": "Home",
@@ -1261,16 +1246,10 @@ _ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
1261
1246
  };
1262
1247
  /**
1263
1248
  * Maps component names to chunk names based on vite.config.ts manualChunks strategy
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.
1249
+ * Each component is assigned to a specific chunk group for code splitting
1269
1250
  *
1270
1251
  * Note: Core components (Home, Dashboard) are not in manual chunks - they're part of main bundle
1271
1252
  * 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.
1274
1253
  */
1275
1254
  _ConfigGenerator.COMPONENT_TO_CHUNK_NAME = {
1276
1255
  // Core components - loaded with main bundle (not code-split)
@@ -1602,6 +1581,7 @@ function smartPrefetch(options = {}) {
1602
1581
  const bqConnector = new BigQueryAnalyticsConnector(
1603
1582
  analytics.credentials.projectId,
1604
1583
  analytics.credentials.datasetId,
1584
+ analytics.credentials.region || "asia-south1",
1605
1585
  debug
1606
1586
  );
1607
1587
  console.log("\n\u{1F3AF} Using real navigation data from BigQuery GA4 export...");