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 +28 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +28 -48
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +1 -13
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +1 -13
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/index.cjs +1 -13
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.js +1 -13
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -37,6 +37,8 @@ interface BigQueryCredentials {
|
|
|
37
37
|
projectId: string;
|
|
38
38
|
/** BigQuery dataset ID (usually analytics_XXXXXXXX) */
|
|
39
39
|
datasetId: string;
|
|
40
|
+
/** BigQuery dataset region (default: asia-south1 for Mumbai, also supports: US, EU, etc.) */
|
|
41
|
+
region?: string;
|
|
40
42
|
}
|
|
41
43
|
interface DataRangeConfig {
|
|
42
44
|
/** Number of days to analyze (default: 30) */
|
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ interface BigQueryCredentials {
|
|
|
37
37
|
projectId: string;
|
|
38
38
|
/** BigQuery dataset ID (usually analytics_XXXXXXXX) */
|
|
39
39
|
datasetId: string;
|
|
40
|
+
/** BigQuery dataset region (default: asia-south1 for Mumbai, also supports: US, EU, etc.) */
|
|
41
|
+
region?: string;
|
|
40
42
|
}
|
|
41
43
|
interface DataRangeConfig {
|
|
42
44
|
/** Number of days to analyze (default: 30) */
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,10 @@ import { BigQuery } from "@google-cloud/bigquery";
|
|
|
3
3
|
import { writeFileSync, mkdirSync } from "fs";
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
var BigQueryAnalyticsConnector = class {
|
|
6
|
-
constructor(projectId, datasetId, debug = false) {
|
|
6
|
+
constructor(projectId, datasetId, location = "asia-south1", debug = false) {
|
|
7
7
|
this.projectId = projectId;
|
|
8
8
|
this.datasetId = datasetId;
|
|
9
|
+
this.location = location;
|
|
9
10
|
this.debug = debug;
|
|
10
11
|
this.bigquery = new BigQuery({
|
|
11
12
|
projectId
|
|
@@ -14,6 +15,7 @@ var BigQueryAnalyticsConnector = class {
|
|
|
14
15
|
console.log("\u2705 BigQuery Analytics connector initialized");
|
|
15
16
|
console.log(` Project ID: ${projectId}`);
|
|
16
17
|
console.log(` Dataset ID: ${datasetId}`);
|
|
18
|
+
console.log(` Location: ${location}`);
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
@@ -72,7 +74,7 @@ var BigQueryAnalyticsConnector = class {
|
|
|
72
74
|
}
|
|
73
75
|
const [rows] = await this.bigquery.query({
|
|
74
76
|
query,
|
|
75
|
-
location:
|
|
77
|
+
location: this.location
|
|
76
78
|
});
|
|
77
79
|
if (this.debug) {
|
|
78
80
|
console.log(`\u2705 Query executed successfully`);
|
|
@@ -325,7 +327,7 @@ var BigQueryAnalyticsConnector = class {
|
|
|
325
327
|
}
|
|
326
328
|
const [rows] = await this.bigquery.query({
|
|
327
329
|
query,
|
|
328
|
-
location:
|
|
330
|
+
location: this.location
|
|
329
331
|
});
|
|
330
332
|
if (this.debug) {
|
|
331
333
|
console.log(`\u2705 Query executed successfully`);
|
|
@@ -386,7 +388,7 @@ var BigQueryAnalyticsConnector = class {
|
|
|
386
388
|
const query = `SELECT 1 as test_value`;
|
|
387
389
|
await this.bigquery.query({
|
|
388
390
|
query,
|
|
389
|
-
location:
|
|
391
|
+
location: this.location
|
|
390
392
|
});
|
|
391
393
|
if (this.debug) {
|
|
392
394
|
console.log("\u2705 BigQuery connection test successful");
|
|
@@ -698,14 +700,21 @@ var _ConfigGenerator = class _ConfigGenerator {
|
|
|
698
700
|
}
|
|
699
701
|
prediction.prefetch.forEach((target) => {
|
|
700
702
|
const chunkFile = this.routeToChunk(target.route);
|
|
701
|
-
let imports = [];
|
|
702
703
|
if (chunkFile) {
|
|
703
704
|
const manifestEntry = this.getManifestEntryByFile(chunkFile);
|
|
704
705
|
const importChunkIds = manifestEntry?.imports || [];
|
|
705
|
-
imports = importChunkIds.map((chunkId) => {
|
|
706
|
+
const imports = importChunkIds.map((chunkId) => {
|
|
706
707
|
const entry = this.manifest[chunkId];
|
|
707
708
|
return entry?.file;
|
|
708
709
|
}).filter((file) => !!file);
|
|
710
|
+
prefetchTargets.push({
|
|
711
|
+
...target,
|
|
712
|
+
chunk: chunkFile,
|
|
713
|
+
chunk_prod: chunkFile,
|
|
714
|
+
// NEW: Include production chunk path
|
|
715
|
+
imports
|
|
716
|
+
// Include dependency chunks (resolved to file paths)
|
|
717
|
+
});
|
|
709
718
|
config.chunks[target.route] = chunkFile;
|
|
710
719
|
mappedRoutes++;
|
|
711
720
|
if (this.debug) {
|
|
@@ -722,39 +731,29 @@ var _ConfigGenerator = class _ConfigGenerator {
|
|
|
722
731
|
}
|
|
723
732
|
unmappedRoutes++;
|
|
724
733
|
}
|
|
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
|
-
});
|
|
733
734
|
});
|
|
734
735
|
if (prediction.segments) {
|
|
735
736
|
Object.entries(prediction.segments).forEach(([segment, segmentTargets]) => {
|
|
736
737
|
const segmentPrefetchTargets = [];
|
|
737
738
|
segmentTargets.forEach((target) => {
|
|
738
739
|
const chunkFile = this.routeToChunk(target.route);
|
|
739
|
-
let imports = [];
|
|
740
740
|
if (chunkFile) {
|
|
741
741
|
const manifestEntry = this.getManifestEntryByFile(chunkFile);
|
|
742
742
|
const importChunkIds = manifestEntry?.imports || [];
|
|
743
|
-
imports = importChunkIds.map((chunkId) => {
|
|
743
|
+
const imports = importChunkIds.map((chunkId) => {
|
|
744
744
|
const entry = this.manifest[chunkId];
|
|
745
745
|
return entry?.file;
|
|
746
746
|
}).filter((file) => !!file);
|
|
747
|
+
segmentPrefetchTargets.push({
|
|
748
|
+
...target,
|
|
749
|
+
chunk: chunkFile,
|
|
750
|
+
chunk_prod: chunkFile,
|
|
751
|
+
// NEW: Include production chunk path
|
|
752
|
+
imports
|
|
753
|
+
});
|
|
747
754
|
config.chunks[target.route] = chunkFile;
|
|
748
755
|
totalSegmentRules++;
|
|
749
756
|
}
|
|
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
|
-
});
|
|
758
757
|
});
|
|
759
758
|
if (segmentPrefetchTargets.length > 0) {
|
|
760
759
|
segmentConfigs[segment] = segmentPrefetchTargets;
|
|
@@ -1173,23 +1172,9 @@ var _ConfigGenerator = class _ConfigGenerator {
|
|
|
1173
1172
|
};
|
|
1174
1173
|
/**
|
|
1175
1174
|
* Maps routes to their component names based on vite.config.ts chunk strategy
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
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):
|
|
1175
|
+
* This is derived from the route configuration in src/routes/index.ts
|
|
1176
|
+
* Note: These are the core routes from vite.config.ts chunking strategy
|
|
1177
|
+
* Routes not listed here will fall through to fuzzy matching
|
|
1193
1178
|
*/
|
|
1194
1179
|
_ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
|
|
1195
1180
|
"/": "Home",
|
|
@@ -1225,16 +1210,10 @@ _ConfigGenerator.ROUTE_TO_COMPONENT_NAME = {
|
|
|
1225
1210
|
};
|
|
1226
1211
|
/**
|
|
1227
1212
|
* Maps component names to chunk names based on vite.config.ts manualChunks strategy
|
|
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.
|
|
1213
|
+
* Each component is assigned to a specific chunk group for code splitting
|
|
1233
1214
|
*
|
|
1234
1215
|
* Note: Core components (Home, Dashboard) are not in manual chunks - they're part of main bundle
|
|
1235
1216
|
* 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.
|
|
1238
1217
|
*/
|
|
1239
1218
|
_ConfigGenerator.COMPONENT_TO_CHUNK_NAME = {
|
|
1240
1219
|
// Core components - loaded with main bundle (not code-split)
|
|
@@ -1566,6 +1545,7 @@ function smartPrefetch(options = {}) {
|
|
|
1566
1545
|
const bqConnector = new BigQueryAnalyticsConnector(
|
|
1567
1546
|
analytics.credentials.projectId,
|
|
1568
1547
|
analytics.credentials.datasetId,
|
|
1548
|
+
analytics.credentials.region || "asia-south1",
|
|
1569
1549
|
debug
|
|
1570
1550
|
);
|
|
1571
1551
|
console.log("\n\u{1F3AF} Using real navigation data from BigQuery GA4 export...");
|