@playcraft/build 0.0.15 → 0.0.19
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/analyzers/scene-asset-collector.js +259 -135
- package/dist/audio-optimizer.d.ts +70 -0
- package/dist/audio-optimizer.js +226 -0
- package/dist/base-builder.d.ts +25 -13
- package/dist/base-builder.js +69 -29
- package/dist/engines/engine-detector.d.ts +13 -4
- package/dist/engines/engine-detector.js +74 -10
- package/dist/engines/generic-adapter.d.ts +12 -6
- package/dist/engines/generic-adapter.js +46 -15
- package/dist/engines/index.d.ts +1 -0
- package/dist/engines/index.js +1 -0
- package/dist/engines/playable-scripts-adapter.d.ts +148 -0
- package/dist/engines/playable-scripts-adapter.js +1084 -0
- package/dist/engines/playcanvas-adapter.js +3 -0
- package/dist/generators/config-generator.js +73 -16
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/platforms/google.d.ts +9 -0
- package/dist/platforms/google.js +68 -7
- package/dist/templates/__loading__.js +100 -0
- package/dist/templates/__modules__.js +47 -0
- package/dist/templates/__settings__.template.js +20 -0
- package/dist/templates/__start__.js +332 -0
- package/dist/templates/index.html +18 -0
- package/dist/templates/logo.png +0 -0
- package/dist/templates/manifest.json +1 -0
- package/dist/templates/patches/cannon.min.js +28 -0
- package/dist/templates/patches/lz4.js +10 -0
- package/dist/templates/patches/one-page-http-get.js +20 -0
- package/dist/templates/patches/one-page-inline-game-scripts.js +52 -0
- package/dist/templates/patches/one-page-mraid-resize-canvas.js +46 -0
- package/dist/templates/patches/p2.min.js +27 -0
- package/dist/templates/patches/playcraft-no-xhr.js +76 -0
- package/dist/templates/playcanvas-stable.min.js +16363 -0
- package/dist/templates/styles.css +43 -0
- package/dist/types.d.ts +60 -13
- package/dist/utils/build-mode-detector.js +2 -0
- package/dist/vite/plugin-playcanvas.js +14 -19
- package/dist/vite/plugin-source-builder.js +383 -97
- package/package.json +7 -4
- package/dist/utils/obfuscate.d.ts +0 -42
- package/dist/utils/obfuscate.js +0 -216
- package/dist/vite/plugin-obfuscate.d.ts +0 -22
- package/dist/vite/plugin-obfuscate.js +0 -52
- package/dist/vite/plugin-template-minifier.d.ts +0 -20
- package/dist/vite/plugin-template-minifier.js +0 -392
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
html {
|
|
2
|
+
height: 100%;
|
|
3
|
+
width: 100%;
|
|
4
|
+
background-color: #1d292c;
|
|
5
|
+
}
|
|
6
|
+
body {
|
|
7
|
+
margin: 0;
|
|
8
|
+
max-height: 100%;
|
|
9
|
+
height: 100%;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
background-color: #1d292c;
|
|
12
|
+
font-family: Helvetica, arial, sans-serif;
|
|
13
|
+
position: relative;
|
|
14
|
+
width: 100%;
|
|
15
|
+
|
|
16
|
+
-webkit-tap-highlight-color: transparent;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#application-canvas {
|
|
20
|
+
display: block;
|
|
21
|
+
position: absolute;
|
|
22
|
+
top: 0;
|
|
23
|
+
left: 0;
|
|
24
|
+
right: 0;
|
|
25
|
+
bottom: 0;
|
|
26
|
+
}
|
|
27
|
+
#application-canvas.fill-mode-NONE {
|
|
28
|
+
margin: auto;
|
|
29
|
+
}
|
|
30
|
+
#application-canvas.fill-mode-KEEP_ASPECT {
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: auto;
|
|
33
|
+
margin: 0;
|
|
34
|
+
}
|
|
35
|
+
#application-canvas.fill-mode-FILL_WINDOW {
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
margin: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
canvas:focus {
|
|
42
|
+
outline: none;
|
|
43
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -56,6 +56,10 @@ export interface BaseBuildMetadata {
|
|
|
56
56
|
imports: Record<string, string>;
|
|
57
57
|
};
|
|
58
58
|
entryPoint?: string;
|
|
59
|
+
engine?: EngineType;
|
|
60
|
+
buildTool?: BuildTool;
|
|
61
|
+
skipChannelBuild?: boolean;
|
|
62
|
+
buildOutputDir?: string;
|
|
59
63
|
}
|
|
60
64
|
export interface LocalBuildOptions {
|
|
61
65
|
scriptsConcatenate?: boolean;
|
|
@@ -116,6 +120,62 @@ export interface SizeReport {
|
|
|
116
120
|
* 支持的引擎类型
|
|
117
121
|
*/
|
|
118
122
|
export type EngineType = 'playcanvas' | 'phaser' | 'pixijs' | 'threejs' | 'cocos' | 'babylonjs' | 'layaair' | 'egret' | 'generic';
|
|
123
|
+
/**
|
|
124
|
+
* 构建工具类型
|
|
125
|
+
* 与引擎类型正交,决定使用哪个构建适配器
|
|
126
|
+
*/
|
|
127
|
+
export type BuildTool = 'playable-scripts' | 'playcanvas-native' | 'generic';
|
|
128
|
+
/**
|
|
129
|
+
* 引擎 + 构建工具 二维检测结果
|
|
130
|
+
*/
|
|
131
|
+
export interface DetectionResult {
|
|
132
|
+
engine: EngineType;
|
|
133
|
+
buildTool: BuildTool;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* PlayableScripts 构建配置
|
|
137
|
+
* 对应 playcraft.config.json 中的 build.playableScripts 配置节
|
|
138
|
+
*
|
|
139
|
+
* 注意:@playcraft/devkit 是用户项目的 npm devDependency,
|
|
140
|
+
* PlayCraft 只负责检测其存在并传递配置参数。
|
|
141
|
+
*/
|
|
142
|
+
export interface PlayableScriptsConfig {
|
|
143
|
+
/** 目标渠道列表(覆盖项目自带的 builds.config.js 中的 channels) */
|
|
144
|
+
channels?: string[];
|
|
145
|
+
/** 主题配置 */
|
|
146
|
+
themes?: {
|
|
147
|
+
enabled?: boolean;
|
|
148
|
+
whitelist?: string[];
|
|
149
|
+
sourceDir?: string;
|
|
150
|
+
entryFile?: string;
|
|
151
|
+
};
|
|
152
|
+
/** 代码混淆等级 (1-4,PlayCraft 默认强制 4) */
|
|
153
|
+
obfuscateLevel?: number;
|
|
154
|
+
/** fflate 压缩(PlayCraft 默认强制 true) */
|
|
155
|
+
fflateCompression?: boolean;
|
|
156
|
+
/** 并发数(默认自动: CPU核心数-1, 最小2最大8) */
|
|
157
|
+
parallel?: number;
|
|
158
|
+
/** 输出目录(默认 dist) */
|
|
159
|
+
outputDir?: string;
|
|
160
|
+
/** 输出为 ZIP 格式(默认 false) */
|
|
161
|
+
zip?: boolean;
|
|
162
|
+
/** 自定义文件名格式(例如: {app}_{name}_{version}_{date}_{language}_{network}) */
|
|
163
|
+
filename?: string;
|
|
164
|
+
/** 所有渠道输出为 ZIP(默认 false) */
|
|
165
|
+
isChannelFold2zip?: boolean;
|
|
166
|
+
/** 文件命名配置 */
|
|
167
|
+
naming?: {
|
|
168
|
+
language?: string;
|
|
169
|
+
format?: string;
|
|
170
|
+
supplier?: string;
|
|
171
|
+
follower?: string;
|
|
172
|
+
};
|
|
173
|
+
/** 商店跳转地址(iOS 和 Android) */
|
|
174
|
+
storeUrls?: {
|
|
175
|
+
ios: string;
|
|
176
|
+
android: string;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
119
179
|
/**
|
|
120
180
|
* 引擎能力集,驱动前端 UI 和 CLI 的条件逻辑
|
|
121
181
|
*/
|
|
@@ -159,19 +219,6 @@ export interface BaseBuildOutput {
|
|
|
159
219
|
assets: string[];
|
|
160
220
|
};
|
|
161
221
|
}
|
|
162
|
-
/**
|
|
163
|
-
* 扩展 BaseBuildMetadata,增加引擎类型
|
|
164
|
-
*/
|
|
165
|
-
export interface BaseBuildMetadata {
|
|
166
|
-
mode: BuildMode;
|
|
167
|
-
engine: EngineType;
|
|
168
|
-
importMap?: {
|
|
169
|
-
id: string;
|
|
170
|
-
imports: Record<string, string>;
|
|
171
|
-
};
|
|
172
|
-
entryPoint?: string;
|
|
173
|
-
buildOutputDir?: string;
|
|
174
|
-
}
|
|
175
222
|
/**
|
|
176
223
|
* 扩展 BuildOptions,增加引擎类型
|
|
177
224
|
*/
|
|
@@ -16,6 +16,7 @@ export async function detectBuildMode(baseBuildDir) {
|
|
|
16
16
|
return {
|
|
17
17
|
mode: 'esm',
|
|
18
18
|
engine: 'playcanvas', // 默认 PlayCanvas,从元数据文件读取时会覆盖
|
|
19
|
+
buildTool: 'generic', // 检测已有产物,构建工具未知
|
|
19
20
|
importMap: {
|
|
20
21
|
id: 'detected',
|
|
21
22
|
imports: importMapContent.imports || {},
|
|
@@ -27,6 +28,7 @@ export async function detectBuildMode(baseBuildDir) {
|
|
|
27
28
|
return {
|
|
28
29
|
mode: 'classic',
|
|
29
30
|
engine: 'playcanvas', // 默认 PlayCanvas,从元数据文件读取时会覆盖
|
|
31
|
+
buildTool: 'generic', // 检测已有产物,构建工具未知
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
@@ -174,12 +174,12 @@ async function generateAndInlineSettings(html, baseBuildDir, options, pluginCont
|
|
|
174
174
|
const configPath = path.join(baseBuildDir, 'config.json');
|
|
175
175
|
const configContent = await fs.readFile(configPath, 'utf-8');
|
|
176
176
|
let configJson = JSON.parse(configContent);
|
|
177
|
-
if (options.convertDataUrls) {
|
|
178
|
-
configJson = await inlineConfigAssetUrls(configJson, baseBuildDir, pluginContext);
|
|
179
|
-
}
|
|
180
177
|
if (options.ammoReplacement) {
|
|
181
178
|
configJson = stripAmmoAssets(configJson);
|
|
182
179
|
}
|
|
180
|
+
if (options.convertDataUrls) {
|
|
181
|
+
configJson = await inlineConfigAssetUrls(configJson, baseBuildDir, pluginContext);
|
|
182
|
+
}
|
|
183
183
|
if (options.mraidSupport) {
|
|
184
184
|
configJson = applyMraidConfig(configJson);
|
|
185
185
|
}
|
|
@@ -254,14 +254,14 @@ async function inlineESMBundleAssets(html, baseBuildDir, options, pluginContext)
|
|
|
254
254
|
console.warn(`[PlayCanvasPlugin] ESM Bundle: 无法读取 config.json: ${error}`);
|
|
255
255
|
return html;
|
|
256
256
|
}
|
|
257
|
-
// 2.
|
|
258
|
-
if (options.convertDataUrls) {
|
|
259
|
-
configJson = await inlineConfigAssetUrls(configJson, baseBuildDir, pluginContext);
|
|
260
|
-
}
|
|
261
|
-
// 3. 处理 Ammo 物理引擎替换
|
|
257
|
+
// 2. 处理 Ammo 物理引擎替换
|
|
262
258
|
if (options.ammoReplacement) {
|
|
263
259
|
configJson = stripAmmoAssets(configJson);
|
|
264
260
|
}
|
|
261
|
+
// 3. 内联 config.json 中的所有资源 URL
|
|
262
|
+
if (options.convertDataUrls) {
|
|
263
|
+
configJson = await inlineConfigAssetUrls(configJson, baseBuildDir, pluginContext);
|
|
264
|
+
}
|
|
265
265
|
// 4. 应用 MRAID 配置
|
|
266
266
|
if (options.mraidSupport) {
|
|
267
267
|
configJson = applyMraidConfig(configJson);
|
|
@@ -462,12 +462,12 @@ async function convertConfigUrl(settingsCode, baseBuildDir, options, pluginConte
|
|
|
462
462
|
try {
|
|
463
463
|
const configContent = await fs.readFile(fullConfigPath, 'utf-8');
|
|
464
464
|
let configJson = JSON.parse(configContent);
|
|
465
|
-
if (options.convertDataUrls) {
|
|
466
|
-
configJson = await inlineConfigAssetUrls(configJson, baseBuildDir, pluginContext);
|
|
467
|
-
}
|
|
468
465
|
if (options.ammoReplacement) {
|
|
469
466
|
configJson = stripAmmoAssets(configJson);
|
|
470
467
|
}
|
|
468
|
+
if (options.convertDataUrls) {
|
|
469
|
+
configJson = await inlineConfigAssetUrls(configJson, baseBuildDir, pluginContext);
|
|
470
|
+
}
|
|
471
471
|
if (options.mraidSupport) {
|
|
472
472
|
configJson = applyMraidConfig(configJson);
|
|
473
473
|
}
|
|
@@ -1072,17 +1072,11 @@ async function inlineConfigAssetUrls(configJson, baseBuildDir, pluginContext) {
|
|
|
1072
1072
|
// 输出统计信息
|
|
1073
1073
|
if (optimizedAssets.length > 0) {
|
|
1074
1074
|
console.log(`\n✅ 通过 Vite 优化了 ${optimizedAssets.length} 个资源:`);
|
|
1075
|
-
optimizedAssets.
|
|
1076
|
-
if (optimizedAssets.length > 5) {
|
|
1077
|
-
console.log(` ... 还有 ${optimizedAssets.length - 5} 个资源`);
|
|
1078
|
-
}
|
|
1075
|
+
optimizedAssets.forEach(info => console.log(` - ${info}`));
|
|
1079
1076
|
}
|
|
1080
1077
|
if (skippedAssets.length > 0) {
|
|
1081
1078
|
console.log(`\n⚠️ 已跳过 ${skippedAssets.length} 个大型资源文件 (>1MB):`);
|
|
1082
|
-
skippedAssets.
|
|
1083
|
-
if (skippedAssets.length > 10) {
|
|
1084
|
-
console.log(` ... 还有 ${skippedAssets.length - 10} 个文件`);
|
|
1085
|
-
}
|
|
1079
|
+
skippedAssets.forEach(name => console.log(` - ${name}`));
|
|
1086
1080
|
}
|
|
1087
1081
|
if (skippedScripts.length > 0) {
|
|
1088
1082
|
console.log(`\n📦 跳过了 ${skippedScripts.length} 个脚本资源(已打包到 __game-scripts.js)`);
|
|
@@ -1319,6 +1313,7 @@ function stripAmmoAssets(configJson) {
|
|
|
1319
1313
|
fileUrl.includes('ammo') ||
|
|
1320
1314
|
fileName.includes('ammo') ||
|
|
1321
1315
|
assetName.includes('ammo')) {
|
|
1316
|
+
console.log(`[ConfigGenerator] 移除 ammo 资源: ${id} - ${moduleName} ${fileName} ${assetName}`);
|
|
1322
1317
|
delete assets[id];
|
|
1323
1318
|
}
|
|
1324
1319
|
}
|