@playcraft/build 0.0.4 → 0.0.8

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 (64) hide show
  1. package/dist/analyzers/scene-asset-collector.js +210 -1
  2. package/dist/base-builder.d.ts +15 -0
  3. package/dist/base-builder.js +192 -16
  4. package/dist/generators/config-generator.js +29 -3
  5. package/dist/loaders/playcanvas-loader.d.ts +7 -0
  6. package/dist/loaders/playcanvas-loader.js +53 -3
  7. package/dist/platforms/adikteev.d.ts +10 -0
  8. package/dist/platforms/adikteev.js +72 -0
  9. package/dist/platforms/base.d.ts +12 -0
  10. package/dist/platforms/base.js +208 -0
  11. package/dist/platforms/facebook.js +5 -2
  12. package/dist/platforms/index.d.ts +4 -0
  13. package/dist/platforms/index.js +16 -0
  14. package/dist/platforms/inmobi.d.ts +10 -0
  15. package/dist/platforms/inmobi.js +68 -0
  16. package/dist/platforms/ironsource.js +5 -2
  17. package/dist/platforms/moloco.js +5 -2
  18. package/dist/platforms/playcraft.d.ts +33 -0
  19. package/dist/platforms/playcraft.js +44 -0
  20. package/dist/platforms/remerge.d.ts +10 -0
  21. package/dist/platforms/remerge.js +56 -0
  22. package/dist/templates/__loading__.js +100 -0
  23. package/dist/templates/__modules__.js +47 -0
  24. package/dist/templates/__settings__.template.js +20 -0
  25. package/dist/templates/__start__.js +332 -0
  26. package/dist/templates/index.html +18 -0
  27. package/dist/templates/logo.png +0 -0
  28. package/dist/templates/manifest.json +1 -0
  29. package/dist/templates/patches/cannon.min.js +28 -0
  30. package/dist/templates/patches/lz4.js +10 -0
  31. package/dist/templates/patches/one-page-http-get.js +20 -0
  32. package/dist/templates/patches/one-page-inline-game-scripts.js +52 -0
  33. package/dist/templates/patches/one-page-mraid-resize-canvas.js +46 -0
  34. package/dist/templates/patches/p2.min.js +27 -0
  35. package/dist/templates/patches/playcraft-no-xhr.js +76 -0
  36. package/dist/templates/playcanvas-stable.min.js +16363 -0
  37. package/dist/templates/styles.css +43 -0
  38. package/dist/types.d.ts +14 -1
  39. package/dist/utils/build-mode-detector.d.ts +9 -0
  40. package/dist/utils/build-mode-detector.js +42 -0
  41. package/dist/vite/config-builder.d.ts +29 -1
  42. package/dist/vite/config-builder.js +169 -25
  43. package/dist/vite/platform-configs.d.ts +4 -0
  44. package/dist/vite/platform-configs.js +97 -13
  45. package/dist/vite/plugin-esm-html-generator.d.ts +22 -0
  46. package/dist/vite/plugin-esm-html-generator.js +1061 -0
  47. package/dist/vite/plugin-platform.js +56 -17
  48. package/dist/vite/plugin-playcanvas.d.ts +2 -0
  49. package/dist/vite/plugin-playcanvas.js +497 -40
  50. package/dist/vite/plugin-source-builder.d.ts +3 -0
  51. package/dist/vite/plugin-source-builder.js +886 -19
  52. package/dist/vite-builder.d.ts +19 -2
  53. package/dist/vite-builder.js +162 -12
  54. package/package.json +2 -1
  55. package/physics/cannon-es-bundle.js +13092 -0
  56. package/physics/cannon-rigidbody-adapter.js +375 -0
  57. package/physics/connon-integration.js +411 -0
  58. package/templates/__start__.js +8 -3
  59. package/templates/index.esm.html +20 -0
  60. package/templates/index.esm.mjs +502 -0
  61. package/templates/patches/one-page-inline-game-scripts.js +25 -1
  62. package/templates/patches/playcraft-cta-adapter.js +297 -0
  63. package/templates/patches/playcraft-no-xhr.js +25 -1
  64. package/templates/playcanvas-esm-wrapper.mjs +827 -0
@@ -2,12 +2,44 @@
2
2
  * 平台配置映射
3
3
  */
4
4
  export const PLATFORM_CONFIGS = {
5
+ playcraft: {
6
+ sizeLimit: Infinity, // 无大小限制
7
+ outputFormat: 'zip',
8
+ minifyCSS: true,
9
+ minifyJS: true,
10
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
11
+ compressModels: true,
12
+ outputFileName: 'index.html',
13
+ includeSourcemap: true, // 通用构建包含 sourcemap
14
+ imageQuality: {
15
+ jpg: 85,
16
+ png: [0.8, 0.9],
17
+ webp: 85,
18
+ },
19
+ modelCompression: {
20
+ method: 'draco',
21
+ quality: 0.9,
22
+ },
23
+ esmSupport: {
24
+ enabled: true,
25
+ preferIIFE: false, // 通用构建支持现代 ESM
26
+ },
27
+ playable: {
28
+ patchXhrOut: false,
29
+ inlineGameScripts: false,
30
+ compressEngine: false,
31
+ configJsonInline: false,
32
+ externFiles: true, // 允许外部文件
33
+ mraidSupport: false,
34
+ snapchatCta: false,
35
+ },
36
+ },
5
37
  facebook: {
6
38
  sizeLimit: 5 * 1024 * 1024, // 5MB(HTML/ZIP 总包体)
7
39
  outputFormat: 'html',
8
40
  minifyCSS: true,
9
41
  minifyJS: true,
10
- compressImages: true,
42
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
11
43
  compressModels: true,
12
44
  injectScripts: ['fbPlayableAd'],
13
45
  outputFileName: 'index.html',
@@ -21,6 +53,10 @@ export const PLATFORM_CONFIGS = {
21
53
  method: 'draco',
22
54
  quality: 0.8,
23
55
  },
56
+ esmSupport: {
57
+ enabled: true, // Facebook 支持现代浏览器特性
58
+ preferIIFE: true, // 但推荐使用 IIFE(更好的兼容性)
59
+ },
24
60
  playable: {
25
61
  patchXhrOut: true,
26
62
  inlineGameScripts: true,
@@ -33,7 +69,7 @@ export const PLATFORM_CONFIGS = {
33
69
  outputFormat: 'zip',
34
70
  minifyCSS: true,
35
71
  minifyJS: true,
36
- compressImages: true,
72
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
37
73
  compressModels: true,
38
74
  injectScripts: ['mraid', 'snapchatCta'],
39
75
  outputFileName: 'ad.html',
@@ -47,6 +83,10 @@ export const PLATFORM_CONFIGS = {
47
83
  method: 'draco',
48
84
  quality: 0.85,
49
85
  },
86
+ esmSupport: {
87
+ enabled: true,
88
+ preferIIFE: true, // Snapchat 推荐 IIFE
89
+ },
50
90
  playable: {
51
91
  inlineGameScripts: true,
52
92
  externFiles: true,
@@ -59,7 +99,7 @@ export const PLATFORM_CONFIGS = {
59
99
  outputFormat: 'html',
60
100
  minifyCSS: true,
61
101
  minifyJS: true,
62
- compressImages: true,
102
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
63
103
  compressModels: true,
64
104
  injectScripts: ['mraid', 'dapi'],
65
105
  outputFileName: 'index.html',
@@ -73,6 +113,10 @@ export const PLATFORM_CONFIGS = {
73
113
  method: 'draco',
74
114
  quality: 0.8,
75
115
  },
116
+ esmSupport: {
117
+ enabled: true,
118
+ preferIIFE: true,
119
+ },
76
120
  playable: {
77
121
  patchXhrOut: true,
78
122
  inlineGameScripts: true,
@@ -85,7 +129,7 @@ export const PLATFORM_CONFIGS = {
85
129
  outputFormat: 'html',
86
130
  minifyCSS: true,
87
131
  minifyJS: true,
88
- compressImages: true,
132
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
89
133
  compressModels: true,
90
134
  injectScripts: ['mraid'],
91
135
  outputFileName: 'index.html',
@@ -99,6 +143,10 @@ export const PLATFORM_CONFIGS = {
99
143
  method: 'draco',
100
144
  quality: 0.8,
101
145
  },
146
+ esmSupport: {
147
+ enabled: true,
148
+ preferIIFE: true,
149
+ },
102
150
  playable: {
103
151
  patchXhrOut: true,
104
152
  inlineGameScripts: true,
@@ -111,7 +159,7 @@ export const PLATFORM_CONFIGS = {
111
159
  outputFormat: 'zip', // ZIP格式(修正)
112
160
  minifyCSS: true,
113
161
  minifyJS: true,
114
- compressImages: true,
162
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
115
163
  compressModels: true,
116
164
  injectScripts: ['exitApi'],
117
165
  outputFileName: 'index.html',
@@ -125,6 +173,10 @@ export const PLATFORM_CONFIGS = {
125
173
  method: 'draco',
126
174
  quality: 0.8,
127
175
  },
176
+ esmSupport: {
177
+ enabled: true,
178
+ preferIIFE: true, // 使用 IIFE 格式确保正确打包(原生 ESM 有兼容性问题)
179
+ },
128
180
  playable: {
129
181
  inlineGameScripts: true,
130
182
  externFiles: true,
@@ -135,7 +187,7 @@ export const PLATFORM_CONFIGS = {
135
187
  outputFormat: 'zip',
136
188
  minifyCSS: true,
137
189
  minifyJS: true,
138
- compressImages: true,
190
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
139
191
  compressModels: true,
140
192
  injectScripts: ['pangleSdk'],
141
193
  outputFileName: 'index.html',
@@ -149,6 +201,10 @@ export const PLATFORM_CONFIGS = {
149
201
  method: 'draco',
150
202
  quality: 0.85,
151
203
  },
204
+ esmSupport: {
205
+ enabled: true,
206
+ preferIIFE: true,
207
+ },
152
208
  playable: {
153
209
  inlineGameScripts: true,
154
210
  externFiles: true,
@@ -159,7 +215,7 @@ export const PLATFORM_CONFIGS = {
159
215
  outputFormat: 'html',
160
216
  minifyCSS: true,
161
217
  minifyJS: true,
162
- compressImages: true,
218
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
163
219
  compressModels: true,
164
220
  injectScripts: ['mraid3'],
165
221
  outputFileName: 'index.html',
@@ -173,6 +229,10 @@ export const PLATFORM_CONFIGS = {
173
229
  method: 'draco',
174
230
  quality: 0.8,
175
231
  },
232
+ esmSupport: {
233
+ enabled: true,
234
+ preferIIFE: true,
235
+ },
176
236
  playable: {
177
237
  patchXhrOut: true,
178
238
  inlineGameScripts: true,
@@ -185,7 +245,7 @@ export const PLATFORM_CONFIGS = {
185
245
  outputFormat: 'zip',
186
246
  minifyCSS: true,
187
247
  minifyJS: true,
188
- compressImages: true,
248
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
189
249
  compressModels: true,
190
250
  injectScripts: ['mraid'],
191
251
  outputFileName: 'index.html',
@@ -199,6 +259,10 @@ export const PLATFORM_CONFIGS = {
199
259
  method: 'draco',
200
260
  quality: 0.8,
201
261
  },
262
+ esmSupport: {
263
+ enabled: true,
264
+ preferIIFE: true,
265
+ },
202
266
  playable: {
203
267
  inlineGameScripts: true,
204
268
  externFiles: true,
@@ -210,7 +274,7 @@ export const PLATFORM_CONFIGS = {
210
274
  outputFormat: 'html',
211
275
  minifyCSS: true,
212
276
  minifyJS: true,
213
- compressImages: true,
277
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
214
278
  compressModels: true,
215
279
  injectScripts: ['fbPlayableAd'],
216
280
  outputFileName: 'index.html',
@@ -224,6 +288,10 @@ export const PLATFORM_CONFIGS = {
224
288
  method: 'draco',
225
289
  quality: 0.8,
226
290
  },
291
+ esmSupport: {
292
+ enabled: true,
293
+ preferIIFE: true,
294
+ },
227
295
  playable: {
228
296
  patchXhrOut: true,
229
297
  inlineGameScripts: true,
@@ -235,7 +303,7 @@ export const PLATFORM_CONFIGS = {
235
303
  outputFormat: 'zip',
236
304
  minifyCSS: true,
237
305
  minifyJS: true,
238
- compressImages: true,
306
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
239
307
  compressModels: true,
240
308
  injectScripts: ['bigoSdk'],
241
309
  outputFileName: 'index.html',
@@ -249,6 +317,10 @@ export const PLATFORM_CONFIGS = {
249
317
  method: 'draco',
250
318
  quality: 0.85,
251
319
  },
320
+ esmSupport: {
321
+ enabled: true,
322
+ preferIIFE: true,
323
+ },
252
324
  playable: {
253
325
  inlineGameScripts: true,
254
326
  externFiles: true,
@@ -259,7 +331,7 @@ export const PLATFORM_CONFIGS = {
259
331
  outputFormat: 'zip',
260
332
  minifyCSS: true,
261
333
  minifyJS: true,
262
- compressImages: true,
334
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
263
335
  compressModels: true,
264
336
  injectScripts: ['mraid'],
265
337
  outputFileName: 'index.html',
@@ -273,6 +345,10 @@ export const PLATFORM_CONFIGS = {
273
345
  method: 'draco',
274
346
  quality: 0.8,
275
347
  },
348
+ esmSupport: {
349
+ enabled: true,
350
+ preferIIFE: true,
351
+ },
276
352
  playable: {
277
353
  inlineGameScripts: true,
278
354
  externFiles: true,
@@ -284,7 +360,7 @@ export const PLATFORM_CONFIGS = {
284
360
  outputFormat: 'html',
285
361
  minifyCSS: true,
286
362
  minifyJS: true,
287
- compressImages: true,
363
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
288
364
  compressModels: true,
289
365
  injectScripts: ['mraid3'],
290
366
  outputFileName: 'index.html',
@@ -298,6 +374,10 @@ export const PLATFORM_CONFIGS = {
298
374
  method: 'draco',
299
375
  quality: 0.8,
300
376
  },
377
+ esmSupport: {
378
+ enabled: true,
379
+ preferIIFE: true,
380
+ },
301
381
  playable: {
302
382
  patchXhrOut: true,
303
383
  inlineGameScripts: true,
@@ -310,7 +390,7 @@ export const PLATFORM_CONFIGS = {
310
390
  outputFormat: 'html',
311
391
  minifyCSS: true,
312
392
  minifyJS: true,
313
- compressImages: true,
393
+ compressImages: false, // 禁用图片压缩,原图输出效果更好
314
394
  compressModels: true,
315
395
  injectScripts: ['fbPlayableAd'],
316
396
  outputFileName: 'index.html',
@@ -324,6 +404,10 @@ export const PLATFORM_CONFIGS = {
324
404
  method: 'draco',
325
405
  quality: 0.8,
326
406
  },
407
+ esmSupport: {
408
+ enabled: true,
409
+ preferIIFE: true,
410
+ },
327
411
  playable: {
328
412
  patchXhrOut: true,
329
413
  inlineGameScripts: true,
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from 'vite';
2
+ export interface ESMBundlePluginOptions {
3
+ baseBuildDir: string;
4
+ outputDir: string;
5
+ minify: boolean;
6
+ }
7
+ /**
8
+ * 预先打包 ESM 脚本为 IIFE
9
+ * 这个函数在主 Vite 构建之前调用
10
+ *
11
+ * 重要:此函数会在临时目录中创建 baseBuildDir 的工作副本,
12
+ * 所有修改都在工作副本中进行,不会影响原始的 baseBuildDir。
13
+ */
14
+ export declare function bundleESMToIIFE(options: ESMBundlePluginOptions): Promise<string>;
15
+ /**
16
+ * ESM Bundle 插件
17
+ *
18
+ * 在 ESM 模式下,将 ESM 用户脚本打包为 IIFE 格式,以便在不支持 ESM 的广告平台上运行。
19
+ *
20
+ * 注意:ESM 打包必须在主构建之前完成,通过 bundleESMToIIFE() 函数预先调用
21
+ */
22
+ export declare function viteESMBundlePlugin(bundledScriptContent: string): Plugin;