@base44-preview/vite-plugin 0.2.16-pr.25.cc5a39c → 0.2.16-pr.25.fd27f29
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injections-plugin.d.ts","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"html-injections-plugin.d.ts","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,MAAM,CAAC;AA4EtD,wBAAgB,oBAAoB,CAAC,EACnC,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,GACjB,EAAE;IACD,WAAW,EAAE,OAAO,CAAC;IACrB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,GA4CM,MAAM,CACZ"}
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
const ANALYTICS_TRACKER_SCRIPT = `
|
|
2
|
+
let lastPath = "";
|
|
3
|
+
function getPageNameFromPath(path) {
|
|
4
|
+
const segments = path.split("/").filter(Boolean);
|
|
5
|
+
return segments[0] || null;
|
|
6
|
+
}
|
|
7
|
+
function trackPageView() {
|
|
8
|
+
const path = window.location.pathname;
|
|
9
|
+
if (path === lastPath) return;
|
|
10
|
+
lastPath = path;
|
|
11
|
+
const pageName = getPageNameFromPath(path) || "home";
|
|
12
|
+
const appId = import.meta.env.VITE_BASE44_APP_ID;
|
|
13
|
+
const serverUrl = import.meta.env.VITE_BASE44_BACKEND_URL || "";
|
|
14
|
+
if (!appId) return;
|
|
15
|
+
fetch(\`\${serverUrl}/app-logs/\${appId}/log-user-in-app/\${pageName}\`, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
}).catch(() => {});
|
|
18
|
+
}
|
|
19
|
+
const originalPushState = history.pushState.bind(history);
|
|
20
|
+
history.pushState = function (...args) {
|
|
21
|
+
originalPushState(...args);
|
|
22
|
+
trackPageView();
|
|
23
|
+
};
|
|
24
|
+
const originalReplaceState = history.replaceState.bind(history);
|
|
25
|
+
history.replaceState = function (...args) {
|
|
26
|
+
originalReplaceState(...args);
|
|
27
|
+
trackPageView();
|
|
28
|
+
};
|
|
29
|
+
window.addEventListener("popstate", trackPageView);
|
|
30
|
+
trackPageView();
|
|
31
|
+
`;
|
|
1
32
|
const INJECTIONS = {
|
|
2
33
|
unhandledErrors: {
|
|
3
34
|
src: "/node_modules/@base44/vite-plugin/dist/injections/unhandled-errors-handlers.js",
|
|
@@ -28,10 +59,10 @@ const INJECTIONS = {
|
|
|
28
59
|
src: "/node_modules/@base44/vite-plugin/dist/injections/analytics-tracker.js",
|
|
29
60
|
injectTo: "head",
|
|
30
61
|
mode: "production",
|
|
62
|
+
inlineContent: ANALYTICS_TRACKER_SCRIPT,
|
|
31
63
|
},
|
|
32
64
|
};
|
|
33
65
|
export function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEditAgent, analyticsTracker, }) {
|
|
34
|
-
// Always-on injections in dev mode
|
|
35
66
|
const enabledInjections = {
|
|
36
67
|
unhandledErrors: true,
|
|
37
68
|
sandboxMount: true,
|
|
@@ -45,18 +76,29 @@ export function htmlInjectionsPlugin({ hmrNotifier, navigationNotifier, visualEd
|
|
|
45
76
|
transformIndexHtml: {
|
|
46
77
|
order: "pre",
|
|
47
78
|
handler(_html, ctx) {
|
|
48
|
-
const
|
|
49
|
-
const currentMode = isProductionBuild ? "production" : "dev";
|
|
79
|
+
const currentMode = ctx.server ? "dev" : "production";
|
|
50
80
|
return Object.entries(INJECTIONS)
|
|
51
81
|
.filter(([key, injection]) => enabledInjections[key] && injection.mode === currentMode)
|
|
52
|
-
.map(([, injection]) =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
82
|
+
.map(([, injection]) => {
|
|
83
|
+
// Production injections use inline content (src paths don't work in built output)
|
|
84
|
+
if (injection.inlineContent) {
|
|
85
|
+
return {
|
|
86
|
+
tag: "script",
|
|
87
|
+
attrs: { type: "module" },
|
|
88
|
+
children: injection.inlineContent,
|
|
89
|
+
injectTo: injection.injectTo,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Dev injections use src path (served from node_modules)
|
|
93
|
+
return {
|
|
94
|
+
tag: "script",
|
|
95
|
+
attrs: {
|
|
96
|
+
src: injection.src,
|
|
97
|
+
type: "module",
|
|
98
|
+
},
|
|
99
|
+
injectTo: injection.injectTo,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
60
102
|
},
|
|
61
103
|
},
|
|
62
104
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injections-plugin.js","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"html-injections-plugin.js","sourceRoot":"","sources":["../src/html-injections-plugin.ts"],"names":[],"mappings":"AAUA,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BhC,CAAC;AAEF,MAAM,UAAU,GAA8B;IAC5C,eAAe,EAAE;QACf,GAAG,EAAE,gFAAgF;QACrF,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,YAAY,EAAE;QACZ,GAAG,EAAE,6EAA6E;QAClF,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,WAAW,EAAE;QACX,GAAG,EAAE,2EAA2E;QAChF,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,kBAAkB,EAAE;QAClB,GAAG,EAAE,0EAA0E;QAC/E,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;KACZ;IACD,eAAe,EAA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b,KAAK,EAAE;4BACL,GAAG,EAAE,SAAS,CAAC,GAAG;4BAClB,IAAI,EAAE,QAAQ;yBACf;wBACD,QAAQ,EAAE,SAAS,CAAC,QAAQ;qBAC7B,CAAC;gBACJ,CAAC,CAAC,CAAC;YACP,CAAC;SACF;KACQ,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,45 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
1
|
+
import type { Plugin, HtmlTagDescriptor } from "vite";
|
|
2
2
|
|
|
3
3
|
type Injection = {
|
|
4
4
|
src: string;
|
|
5
5
|
injectTo: "head" | "body";
|
|
6
6
|
mode: "dev" | "production";
|
|
7
|
+
/** Inline content for production builds (src paths don't work in built output) */
|
|
8
|
+
inlineContent?: string;
|
|
7
9
|
};
|
|
8
10
|
|
|
11
|
+
const ANALYTICS_TRACKER_SCRIPT = `
|
|
12
|
+
let lastPath = "";
|
|
13
|
+
function getPageNameFromPath(path) {
|
|
14
|
+
const segments = path.split("/").filter(Boolean);
|
|
15
|
+
return segments[0] || null;
|
|
16
|
+
}
|
|
17
|
+
function trackPageView() {
|
|
18
|
+
const path = window.location.pathname;
|
|
19
|
+
if (path === lastPath) return;
|
|
20
|
+
lastPath = path;
|
|
21
|
+
const pageName = getPageNameFromPath(path) || "home";
|
|
22
|
+
const appId = import.meta.env.VITE_BASE44_APP_ID;
|
|
23
|
+
const serverUrl = import.meta.env.VITE_BASE44_BACKEND_URL || "";
|
|
24
|
+
if (!appId) return;
|
|
25
|
+
fetch(\`\${serverUrl}/app-logs/\${appId}/log-user-in-app/\${pageName}\`, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
}).catch(() => {});
|
|
28
|
+
}
|
|
29
|
+
const originalPushState = history.pushState.bind(history);
|
|
30
|
+
history.pushState = function (...args) {
|
|
31
|
+
originalPushState(...args);
|
|
32
|
+
trackPageView();
|
|
33
|
+
};
|
|
34
|
+
const originalReplaceState = history.replaceState.bind(history);
|
|
35
|
+
history.replaceState = function (...args) {
|
|
36
|
+
originalReplaceState(...args);
|
|
37
|
+
trackPageView();
|
|
38
|
+
};
|
|
39
|
+
window.addEventListener("popstate", trackPageView);
|
|
40
|
+
trackPageView();
|
|
41
|
+
`;
|
|
42
|
+
|
|
9
43
|
const INJECTIONS: Record<string, Injection> = {
|
|
10
44
|
unhandledErrors: {
|
|
11
45
|
src: "/node_modules/@base44/vite-plugin/dist/injections/unhandled-errors-handlers.js",
|
|
@@ -36,6 +70,7 @@ const INJECTIONS: Record<string, Injection> = {
|
|
|
36
70
|
src: "/node_modules/@base44/vite-plugin/dist/injections/analytics-tracker.js",
|
|
37
71
|
injectTo: "head",
|
|
38
72
|
mode: "production",
|
|
73
|
+
inlineContent: ANALYTICS_TRACKER_SCRIPT,
|
|
39
74
|
},
|
|
40
75
|
};
|
|
41
76
|
|
|
@@ -50,7 +85,6 @@ export function htmlInjectionsPlugin({
|
|
|
50
85
|
visualEditAgent: boolean;
|
|
51
86
|
analyticsTracker: boolean;
|
|
52
87
|
}) {
|
|
53
|
-
// Always-on injections in dev mode
|
|
54
88
|
const enabledInjections: Record<string, boolean> = {
|
|
55
89
|
unhandledErrors: true,
|
|
56
90
|
sandboxMount: true,
|
|
@@ -65,21 +99,33 @@ export function htmlInjectionsPlugin({
|
|
|
65
99
|
transformIndexHtml: {
|
|
66
100
|
order: "pre",
|
|
67
101
|
handler(_html, ctx) {
|
|
68
|
-
const
|
|
69
|
-
const currentMode = isProductionBuild ? "production" : "dev";
|
|
102
|
+
const currentMode = ctx.server ? "dev" : "production";
|
|
70
103
|
|
|
71
104
|
return Object.entries(INJECTIONS)
|
|
72
|
-
.filter(
|
|
73
|
-
|
|
105
|
+
.filter(
|
|
106
|
+
([key, injection]) =>
|
|
107
|
+
enabledInjections[key] && injection.mode === currentMode
|
|
74
108
|
)
|
|
75
|
-
.map(([, injection]) =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
.map(([, injection]): HtmlTagDescriptor => {
|
|
110
|
+
// Production injections use inline content (src paths don't work in built output)
|
|
111
|
+
if (injection.inlineContent) {
|
|
112
|
+
return {
|
|
113
|
+
tag: "script",
|
|
114
|
+
attrs: { type: "module" },
|
|
115
|
+
children: injection.inlineContent,
|
|
116
|
+
injectTo: injection.injectTo,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// Dev injections use src path (served from node_modules)
|
|
120
|
+
return {
|
|
121
|
+
tag: "script",
|
|
122
|
+
attrs: {
|
|
123
|
+
src: injection.src,
|
|
124
|
+
type: "module",
|
|
125
|
+
},
|
|
126
|
+
injectTo: injection.injectTo,
|
|
127
|
+
};
|
|
128
|
+
});
|
|
83
129
|
},
|
|
84
130
|
},
|
|
85
131
|
} as Plugin;
|