@playcademy/vite-plugin 0.1.25 → 0.1.26-alpha.1
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/README.md +40 -20
- package/dist/config/proxy.d.ts +12 -0
- package/dist/config/vite-config.d.ts +8 -0
- package/dist/hooks/close-bundle.d.ts +9 -0
- package/dist/hooks/config-resolved.d.ts +10 -0
- package/dist/hooks/config.d.ts +10 -0
- package/dist/hooks/configure-server.d.ts +10 -0
- package/dist/hooks/write-bundle.d.ts +9 -0
- package/dist/index.d.ts +3 -7
- package/dist/index.js +37775 -37647
- package/dist/lib/backend/hot-reload.d.ts +11 -0
- package/dist/lib/backend/index.d.ts +5 -0
- package/dist/lib/{cli-server.d.ts → backend/server.d.ts} +1 -1
- package/dist/lib/build/index.d.ts +4 -0
- package/dist/lib/{manifest.d.ts → build/manifest.d.ts} +2 -2
- package/dist/lib/logging/adapter.d.ts +19 -0
- package/dist/lib/logging/index.d.ts +6 -0
- package/dist/lib/{logging.d.ts → logging/utils.d.ts} +3 -3
- package/dist/lib/sandbox/index.d.ts +6 -0
- package/dist/lib/sandbox/project-info.d.ts +10 -0
- package/dist/lib/{sandbox.d.ts → sandbox/server.d.ts} +2 -1
- package/dist/lib/sandbox/timeback.d.ts +11 -0
- package/dist/plugin.d.ts +15 -0
- package/dist/server/cleanup.d.ts +7 -0
- package/dist/server/lifecycle.d.ts +8 -0
- package/dist/server/platform-mode.d.ts +17 -0
- package/dist/server/standalone-mode.d.ts +9 -0
- package/dist/server/state.d.ts +36 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/internal.d.ts +73 -0
- package/dist/types/options.d.ts +51 -0
- package/package.json +3 -8
- package/dist/types.d.ts +0 -97
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +0 -7
- /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
|
-
|
|
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
|
|
138
|
-
|
|
|
139
|
-
| `
|
|
140
|
-
| `
|
|
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
|
-
"
|
|
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,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
|
-
*
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
export declare function playcademy(options?: PlaycademyPluginOptions): Plugin;
|
|
6
|
+
export { playcademy } from './plugin';
|
|
7
|
+
export type * from './types';
|