同步主站 Cocos 当前工程:关卡资源、运行脚本与打包工具。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -65,6 +65,60 @@ function brotliCompressWebglBundles(webglDir, opts = {}) {
|
||||
return { count, saved };
|
||||
}
|
||||
|
||||
/**
|
||||
* 写出 Cocos loader 只需的 catalog(3 个 bundle 名)。
|
||||
* Unity 原 catalog 含数千 prefab 路径,对 Cocos 无用且首屏白下 ~1 MB。
|
||||
*/
|
||||
function writeSlimCatalog(catalogPath, bundleNames) {
|
||||
const prefix = '{UnityEngine.AddressableAssets.Addressables.RuntimePath}/WebGL/';
|
||||
const ids = [];
|
||||
for (const name of bundleNames) {
|
||||
if (name) ids.push(prefix + name);
|
||||
}
|
||||
const slim = {
|
||||
m_LocatorId: 'AddressablesMainContentCatalog',
|
||||
m_InternalIds: ids,
|
||||
};
|
||||
fs.writeFileSync(catalogPath, JSON.stringify(slim), 'utf8');
|
||||
return Buffer.byteLength(JSON.stringify(slim), 'utf8');
|
||||
}
|
||||
|
||||
/**
|
||||
* 已有 .br 则删掉未压缩原文。loader 优先请求 .br。
|
||||
* 保留 catalog / settings / levels-db-index 明文(很小,便于校验)。
|
||||
* KEEP_PLAIN=1 跳过。
|
||||
*/
|
||||
function stripPlainIfBrotli(root, opts = {}) {
|
||||
if (process.env.KEEP_PLAIN === '1') {
|
||||
return { removed: 0, saved: 0, skipped: true };
|
||||
}
|
||||
const keep = new Set(opts.keepNames || [
|
||||
'catalog.json',
|
||||
'settings.json',
|
||||
'levels-db-index.json',
|
||||
]);
|
||||
let removed = 0;
|
||||
let saved = 0;
|
||||
function walk(dir) {
|
||||
if (!fs.existsSync(dir)) return;
|
||||
for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const p = path.join(dir, ent.name);
|
||||
if (ent.isDirectory()) {
|
||||
walk(p);
|
||||
continue;
|
||||
}
|
||||
if (ent.name.endsWith('.br') || keep.has(ent.name)) continue;
|
||||
const br = `${p}.br`;
|
||||
if (!fs.existsSync(br) || !fs.statSync(br).isFile()) continue;
|
||||
saved += fs.statSync(p).size;
|
||||
fs.unlinkSync(p);
|
||||
removed += 1;
|
||||
}
|
||||
}
|
||||
walk(root);
|
||||
return { removed, saved, skipped: false };
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整预加载 bundle:默认只预加载 main,resources / level-prefabs 按需加载。
|
||||
* @param {object} opts
|
||||
@@ -142,6 +196,8 @@ function printPackageReport(outDir, opts = {}) {
|
||||
['assets/internal', path.join(outDir, 'assets', 'internal')],
|
||||
['levels-database.json', path.join(outDir, 'levels-database.json')],
|
||||
['levels-database.json.br', path.join(outDir, 'levels-database.json.br')],
|
||||
['levels-db-index.json', path.join(outDir, 'levels-db-index.json')],
|
||||
['StreamingAssets', path.join(outDir, 'StreamingAssets')],
|
||||
['Build', path.join(outDir, 'Build')],
|
||||
];
|
||||
let total = 0;
|
||||
@@ -165,6 +221,8 @@ module.exports = {
|
||||
minifyLevelsDatabase,
|
||||
brotliCompressFile,
|
||||
brotliCompressWebglBundles,
|
||||
writeSlimCatalog,
|
||||
stripPlainIfBrotli,
|
||||
patchPreloadSettings,
|
||||
patchSplashSettings,
|
||||
patchSplashInZipBundle,
|
||||
|
||||
Reference in New Issue
Block a user