Skip to content

Commit

Permalink
Add build-engine option visualize.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Feb 23, 2024
1 parent 1e7c303 commit 2a21aac
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 36 deletions.
7 changes: 7 additions & 0 deletions .api/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ declare module "@cocos/ccbuild" {
* @default false
*/
preserveType?: boolean;
visualize?: boolean | {
file?: string;
};
/**
* Generate cocos/native-binding/decorators.ts for native platforms
*/
generateDecoratorsForJSB?: boolean;
/**
* Whether to generate a json file that contains all output script file paths.
*/
Expand Down
3 changes: 3 additions & 0 deletions modules/build-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
"@types/semver": "~7.5.0",
"@types/node": "~20.3.3",
"@types/glob": "~7.2.0"
},
"optionalDependencies": {
"rollup-plugin-visualizer": "5.9.2"
}
}
40 changes: 20 additions & 20 deletions modules/build-engine/src/engine-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,26 @@ export async function buildJsEngine(options: Required<buildEngine.Options>): Pro
}));
}

// const visualizeOptions = typeof options.visualize === 'object'
// ? options.visualize
// : (options.visualize ? {} : undefined);
// if (visualizeOptions) {
// let rpVisualizer;
// try {
// // @ts-expect-error: No typing
// rpVisualizer = await import('rollup-plugin-visualizer');
// } catch {
// console.warn('Visualizing needs \'rollup-plugin-visualizer\' to be installed. It\'s installed as dev-dependency.');
// }
// if (rpVisualizer) {
// const visualizeFile = visualizeOptions.file ?? ps.join(options.out, 'visualize.html');
// rollupPlugins.push(rpVisualizer({
// filename: visualizeFile,
// title: 'Cocos Creator build visualizer',
// template: 'treemap',
// }));
// }
// }
const visualizeOptions = typeof options.visualize === 'object'
? options.visualize
: (options.visualize ? {} : undefined);
if (visualizeOptions) {
let rpVisualizer;
try {
// eslint-disable-next-line import/no-extraneous-dependencies
rpVisualizer = await import('rollup-plugin-visualizer');
} catch {
console.warn('Visualizing needs \'rollup-plugin-visualizer\' to be installed. It\'s installed as dev-dependency.');
}
if (rpVisualizer) {
const visualizeFile = visualizeOptions.file ?? ps.join(options.out, 'visualize.html');
rollupPlugins.push(rpVisualizer.visualizer({
filename: visualizeFile,
title: 'Cocos Creator build visualizer',
template: 'treemap',
}));
}
}

let hasCriticalWarns = false;

Expand Down
6 changes: 3 additions & 3 deletions modules/build-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ export namespace buildEngine {
*/
preserveType?: boolean;

// visualize?: boolean | {
// file?: string;
// };
visualize?: boolean | {
file?: string;
};

// buildTimeConstants: IBuildTimeConstants;

Expand Down
111 changes: 98 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a21aac

Please sign in to comment.