@playcademy/vite-plugin 0.2.29-beta.2 → 0.2.29-beta.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/hooks/transform-index-html.d.ts +27 -0
- package/dist/index.js +38 -2
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite transformIndexHtml() hook
|
|
3
|
+
*
|
|
4
|
+
* Injects a PostHog session replay snippet into game HTML at build time.
|
|
5
|
+
* This enables cross-origin iframe recording: the game iframe's PostHog
|
|
6
|
+
* instance posts its recording data (DOM snapshots, network requests,
|
|
7
|
+
* console logs) to the parent platform's PostHog instance, producing a
|
|
8
|
+
* single unified session replay.
|
|
9
|
+
*
|
|
10
|
+
* The snippet loads before any game JS, so it captures the full boot
|
|
11
|
+
* sequence including asset downloads and JS parse/execute timing — even
|
|
12
|
+
* if the game bundle never finishes loading.
|
|
13
|
+
*
|
|
14
|
+
* Only injected in production builds.
|
|
15
|
+
*/
|
|
16
|
+
import type { HtmlTagDescriptor } from 'vite';
|
|
17
|
+
import type { PluginContext } from '../types';
|
|
18
|
+
/**
|
|
19
|
+
* Transform index.html to inject PostHog cross-origin iframe recording.
|
|
20
|
+
*
|
|
21
|
+
* Returns an array of HTML tag descriptors that Vite injects into the
|
|
22
|
+
* built HTML. The script is placed in `<head>` so it loads before any
|
|
23
|
+
* game scripts in `<body>`.
|
|
24
|
+
*
|
|
25
|
+
* Skipped when running the dev server (not a production build).
|
|
26
|
+
*/
|
|
27
|
+
export declare function transformIndexHtmlHook(context: PluginContext): HtmlTagDescriptor[] | undefined;
|
package/dist/index.js
CHANGED
|
@@ -25370,7 +25370,7 @@ var package_default;
|
|
|
25370
25370
|
var init_package = __esm(() => {
|
|
25371
25371
|
package_default = {
|
|
25372
25372
|
name: "@playcademy/sandbox",
|
|
25373
|
-
version: "0.3.17-beta.
|
|
25373
|
+
version: "0.3.17-beta.33",
|
|
25374
25374
|
description: "Local development server for Playcademy game development",
|
|
25375
25375
|
type: "module",
|
|
25376
25376
|
exports: {
|
|
@@ -126509,6 +126509,12 @@ var TYPESCRIPT_RUNNER2 = {
|
|
|
126509
126509
|
package: TypeScriptPackages2.nativePreviewBeta,
|
|
126510
126510
|
bin: "tsgo"
|
|
126511
126511
|
};
|
|
126512
|
+
// ../constants/src/domains.ts
|
|
126513
|
+
var POSTHOG_CONFIG = {
|
|
126514
|
+
apiKey: "phc_z7aVQnB4P9FHm91g0BSfJTlIU6lISCBVhIJEFdfnYfX",
|
|
126515
|
+
host: "https://e.playcademy.net",
|
|
126516
|
+
uiHost: "https://us.posthog.com"
|
|
126517
|
+
};
|
|
126512
126518
|
// ../constants/src/overworld.ts
|
|
126513
126519
|
var ITEM_SLUGS2 = {
|
|
126514
126520
|
PLAYCADEMY_CREDITS: "PLAYCADEMY_CREDITS",
|
|
@@ -127578,7 +127584,7 @@ var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
|
127578
127584
|
// package.json
|
|
127579
127585
|
var package_default2 = {
|
|
127580
127586
|
name: "@playcademy/vite-plugin",
|
|
127581
|
-
version: "0.2.29-beta.
|
|
127587
|
+
version: "0.2.29-beta.3",
|
|
127582
127588
|
type: "module",
|
|
127583
127589
|
exports: {
|
|
127584
127590
|
".": {
|
|
@@ -127932,6 +127938,35 @@ async function configureServerHook(server, context) {
|
|
|
127932
127938
|
}
|
|
127933
127939
|
}
|
|
127934
127940
|
|
|
127941
|
+
// src/hooks/transform-index-html.ts
|
|
127942
|
+
var POSTHOG_LOADER = '!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug getPageViewId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);';
|
|
127943
|
+
var POSTHOG_INSTANCE_NAME = "playcademy_iframe";
|
|
127944
|
+
function buildInitCall() {
|
|
127945
|
+
const config2 = [
|
|
127946
|
+
`api_host:'${POSTHOG_CONFIG.host}'`,
|
|
127947
|
+
`ui_host:'${POSTHOG_CONFIG.uiHost}'`,
|
|
127948
|
+
"autocapture:false",
|
|
127949
|
+
"capture_pageview:false",
|
|
127950
|
+
"capture_pageleave:false",
|
|
127951
|
+
"capture_heatmaps:false",
|
|
127952
|
+
"disable_persistence:true",
|
|
127953
|
+
"session_recording:{recordCrossOriginIframes:true}"
|
|
127954
|
+
].join(",");
|
|
127955
|
+
return `posthog.init('${POSTHOG_CONFIG.apiKey}',{${config2}},'${POSTHOG_INSTANCE_NAME}');`;
|
|
127956
|
+
}
|
|
127957
|
+
function transformIndexHtmlHook(context) {
|
|
127958
|
+
if (context.viteConfig?.command !== "build") {
|
|
127959
|
+
return;
|
|
127960
|
+
}
|
|
127961
|
+
return [
|
|
127962
|
+
{
|
|
127963
|
+
tag: "script",
|
|
127964
|
+
children: POSTHOG_LOADER + buildInitCall(),
|
|
127965
|
+
injectTo: "head"
|
|
127966
|
+
}
|
|
127967
|
+
];
|
|
127968
|
+
}
|
|
127969
|
+
|
|
127935
127970
|
// src/hooks/write-bundle.ts
|
|
127936
127971
|
import path6 from "node:path";
|
|
127937
127972
|
async function writeBundleHook(context) {
|
|
@@ -127990,6 +128025,7 @@ function playcademy(options = {}) {
|
|
|
127990
128025
|
config: (userConfig) => configHook(userConfig, context),
|
|
127991
128026
|
configResolved: (resolvedConfig) => configResolvedHook(resolvedConfig, context),
|
|
127992
128027
|
configureServer: (server) => configureServerHook(server, context),
|
|
128028
|
+
transformIndexHtml: () => transformIndexHtmlHook(context),
|
|
127993
128029
|
writeBundle: () => writeBundleHook(context),
|
|
127994
128030
|
closeBundle: () => closeBundleHook(context)
|
|
127995
128031
|
};
|