@playcademy/vite-plugin 0.1.25 → 0.1.26-alpha.2

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.
Files changed (37) hide show
  1. package/README.md +40 -20
  2. package/dist/config/proxy.d.ts +12 -0
  3. package/dist/config/vite-config.d.ts +8 -0
  4. package/dist/hooks/close-bundle.d.ts +9 -0
  5. package/dist/hooks/config-resolved.d.ts +10 -0
  6. package/dist/hooks/config.d.ts +10 -0
  7. package/dist/hooks/configure-server.d.ts +10 -0
  8. package/dist/hooks/write-bundle.d.ts +9 -0
  9. package/dist/index.d.ts +3 -7
  10. package/dist/index.js +37983 -37785
  11. package/dist/lib/backend/hot-reload.d.ts +11 -0
  12. package/dist/lib/backend/index.d.ts +5 -0
  13. package/dist/lib/{cli-server.d.ts → backend/server.d.ts} +1 -1
  14. package/dist/lib/build/index.d.ts +4 -0
  15. package/dist/lib/{manifest.d.ts → build/manifest.d.ts} +2 -2
  16. package/dist/lib/logging/adapter.d.ts +19 -0
  17. package/dist/lib/logging/index.d.ts +6 -0
  18. package/dist/lib/{logging.d.ts → logging/utils.d.ts} +3 -3
  19. package/dist/lib/sandbox/index.d.ts +6 -0
  20. package/dist/lib/sandbox/project-info.d.ts +10 -0
  21. package/dist/lib/{sandbox.d.ts → sandbox/server.d.ts} +2 -1
  22. package/dist/lib/sandbox/timeback.d.ts +11 -0
  23. package/dist/plugin.d.ts +15 -0
  24. package/dist/server/cleanup.d.ts +7 -0
  25. package/dist/server/lifecycle.d.ts +8 -0
  26. package/dist/server/mode-switcher.d.ts +14 -0
  27. package/dist/server/platform-mode.d.ts +17 -0
  28. package/dist/server/standalone-mode.d.ts +9 -0
  29. package/dist/server/state.d.ts +56 -0
  30. package/dist/types/index.d.ts +5 -0
  31. package/dist/types/internal.d.ts +73 -0
  32. package/dist/types/options.d.ts +51 -0
  33. package/package.json +5 -10
  34. package/dist/types.d.ts +0 -97
  35. package/dist/types.js +0 -0
  36. package/dist/utils.d.ts +0 -7
  37. /package/dist/{lib/server.d.ts → server/middleware.d.ts} +0 -0
package/README.md CHANGED
@@ -78,11 +78,8 @@ export default defineConfig({
78
78
  plugins: [
79
79
  playcademy({
80
80
  export: {
81
- bootMode: 'iframe', // 'iframe' | 'module'
82
- entryPoint: 'index.html', // Main HTML file
83
- platform: 'web', // 'web' | 'godot' | 'unity'
81
+ platform: 'web', // Platform identifier (auto-detected)
84
82
  autoZip: false, // Create deployment zip
85
- styles: [], // Additional CSS files
86
83
  },
87
84
  sandbox: {
88
85
  autoStart: true, // Start sandbox automatically
@@ -134,13 +131,10 @@ export default defineConfig({
134
131
 
135
132
  Configuration for manifest generation and build output:
136
133
 
137
- | Option | Type | Default | Description |
138
- | ------------ | ----------------------------- | -------------- | ------------------------------- |
139
- | `bootMode` | `'iframe' \| 'module'` | `'iframe'` | How the game should be launched |
140
- | `entryPoint` | `string` | `'index.html'` | Main HTML file for your game |
141
- | `platform` | `'web' \| 'godot' \| 'unity'` | `'web'` | Game engine/platform type |
142
- | `autoZip` | `boolean` | `false` | Create deployment zip archive |
143
- | `styles` | `string[]` | `[]` | Additional CSS files to load |
134
+ | Option | Type | Default | Description |
135
+ | ---------- | --------- | ------- | ---------------------------------------------- |
136
+ | `platform` | `string` | `'web'` | Platform identifier (e.g., 'web', 'godot@4.3') |
137
+ | `autoZip` | `boolean` | `false` | Create deployment zip archive |
144
138
 
145
139
  ### Sandbox Options (`sandbox`)
146
140
 
@@ -178,15 +172,47 @@ PLAYCADEMY v1.2.3
178
172
  ➜ Sandbox: http://localhost:4321/api
179
173
  ```
180
174
 
181
- **How it works**: When you visit `http://localhost:5173/` in your browser, you'll see your game wrapped in the Playcademy development shell (which mimics the production platform environment). Inside the iframe, your game is served at the root path `/`, so client-side routers (React Router, etc.) work naturally without any special configuration.
175
+ **How it works**: When you visit `http://localhost:5173/` in your browser, you'll see your game wrapped in the Playcademy development shell (which mimics the production platform environment). Inside the iframe, your game is served at the root path `/`, so client-side routers (React Router, wouter, etc.) work naturally without any special configuration.
182
176
 
183
177
  The plugin uses the `Sec-Fetch-Dest` header to intelligently detect whether a request is from the shell's iframe or top-level browser navigation, automatically serving the appropriate content.
184
178
 
179
+ **Client-side routing**: Both in development and production, your routers will see clean paths like `/` and `/game`. In production, the platform uses a game runner that loads your game from the CDN while presenting clean routing paths. You don't need to configure anything - just write your routes normally:
180
+
181
+ ```tsx
182
+ <Router>
183
+ <Route path="/" component={Home} />
184
+ <Route path="/game" component={Game} />
185
+ <Route path="/settings" component={Settings} />
186
+ </Router>
187
+ ```
188
+
189
+ **Runtime asset loading**: If your game loads assets dynamically at runtime (files that Vite can't analyze at build time), use the SDK's CDN helpers:
190
+
191
+ ```typescript
192
+ import { PlaycademyClient } from '@playcademy/sdk'
193
+
194
+ const client = await PlaycademyClient.init()
195
+
196
+ // Load dynamic JSON data (e.g., level selected by user)
197
+ const levelData = await client.runtime.cdn.json`levels/level-${levelId}.json`
198
+
199
+ // Load images dynamically using tagged template literals
200
+ img.src = client.runtime.cdn.url`badges/${badgeType}.png`
201
+ audio.src = client.runtime.cdn.url`sfx/${soundEffect}.wav`
202
+
203
+ // Or use regular function calls
204
+ const data = await client.runtime.cdn.fetch('data/config.json')
205
+ const blob = await client.runtime.cdn.blob('images/hero.png')
206
+ ```
207
+
208
+ These helpers automatically resolve to the correct CDN path in production and relative paths in local development.
209
+
185
210
  ### Production Build
186
211
 
187
212
  During `bun run build`, the plugin:
188
213
 
189
214
  - Generates `playcademy.manifest.json` in `dist/`
215
+ - Generates `.vite/manifest.json` for optimal asset loading
190
216
  - Creates deployment zip (if `autoZip: true`)
191
217
  - Optimizes build for platform deployment
192
218
 
@@ -209,15 +235,9 @@ The plugin generates `dist/playcademy.manifest.json`:
209
235
 
210
236
  ```json
211
237
  {
212
- "version": 1,
213
- "slug": "my-game",
214
- "displayName": "My Game",
215
- "description": "An awesome Playcademy game",
216
- "entryPoint": "index.html",
217
- "bootMode": "iframe",
238
+ "version": "1",
218
239
  "platform": "web",
219
- "styles": [],
220
- "gameVersion": "1.0.0"
240
+ "createdAt": "2024-01-01T12:00:00.000Z"
221
241
  }
222
242
  ```
223
243
 
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Proxy configuration for backend API
3
+ */
4
+ import type { ProxyOptions } from 'vite';
5
+ export interface ProxyConfig {
6
+ '/api'?: string | ProxyOptions;
7
+ }
8
+ /**
9
+ * Create proxy configuration for backend API
10
+ * Auto-configures /api proxy to route requests to the backend server
11
+ */
12
+ export declare function createProxyConfig(existingProxy: Record<string, string | ProxyOptions>, backendPort: number): Record<string, string | ProxyOptions>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Vite configuration modifications
3
+ */
4
+ import type { UserConfig } from 'vite';
5
+ /**
6
+ * Create Vite configuration with Playcademy-specific settings
7
+ */
8
+ export declare function createViteConfig(userConfig: UserConfig, backendPort: number): UserConfig;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Vite closeBundle() hook
3
+ * Runs after all bundles are closed
4
+ */
5
+ import type { PluginContext } from '../types/internal';
6
+ /**
7
+ * Handle closeBundle hook - performs final logging
8
+ */
9
+ export declare function closeBundleHook(context: PluginContext): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Vite configResolved() hook
3
+ * Runs after Vite config is resolved
4
+ */
5
+ import type { ResolvedConfig } from 'vite';
6
+ import type { PluginContext } from '../types/internal';
7
+ /**
8
+ * Handle configResolved hook - stores resolved config
9
+ */
10
+ export declare function configResolvedHook(resolvedConfig: ResolvedConfig, context: PluginContext): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Vite config() hook
3
+ * Runs before Vite resolves the config
4
+ */
5
+ import type { UserConfig } from 'vite';
6
+ import type { PluginContext } from '../types';
7
+ /**
8
+ * Handle config hook - modifies Vite configuration
9
+ */
10
+ export declare function configHook(userConfig: UserConfig, context: PluginContext): Promise<UserConfig>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Vite configureServer() hook
3
+ * Runs when the dev server is created
4
+ */
5
+ import type { ViteDevServer } from 'vite';
6
+ import type { PluginContext } from '../types/internal';
7
+ /**
8
+ * Handle configureServer hook - sets up dev servers
9
+ */
10
+ export declare function configureServerHook(server: ViteDevServer, context: PluginContext): Promise<void>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Vite writeBundle() hook
3
+ * Runs after bundle is written to disk
4
+ */
5
+ import type { PluginContext } from '../types/internal';
6
+ /**
7
+ * Handle writeBundle hook - generates manifest and optional zip
8
+ */
9
+ export declare function writeBundleHook(context: PluginContext): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  /**
2
2
  * Playcademy Vite Plugin
3
3
  *
4
- * Provides:
5
- * - Auto-starting sandbox server during development
6
- * - Hijacking dev server to serve Playcademy loader environment
7
- * - Build-time manifest generation and optional zip packaging
4
+ * Entry point - exports plugin and types
8
5
  */
9
- import type { Plugin } from 'vite';
10
- import type { PlaycademyPluginOptions } from './types';
11
- export declare function playcademy(options?: PlaycademyPluginOptions): Plugin;
6
+ export { playcademy } from './plugin';
7
+ export type * from './types';