Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"b:types": "pnpm -r --filter=./packages/* run b:types",
"b:module": "cross-env BUILD_TYPE=MODULE NODE_ENV=release rollup -c",
"b:umd": "cross-env BUILD_TYPE=UMD NODE_ENV=release rollup -c",
"b:bundled": "cross-env BUILD_TYPE=BUNDLED NODE_ENV=release rollup -c",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 这里新增了 b:bundled,但当前 CI 主流程的 build 仍是 npm run build(只跑 b:module + b:types),不会覆盖 BUILD_TYPE=BUNDLED。建议补一个最小校验(例如 CI 增加一次 pnpm b:bundled 并检查产物存在),否则这条新构建链路回归时很难在 PR 阶段被拦住。

"b:all": "cross-env NODE_ENV=release npm run b:types && cross-env BUILD_TYPE=ALL NODE_ENV=release rollup -c",
"clean": "pnpm -r exec rm -rf dist && pnpm -r exec rm -rf types",
"e2e:case": "pnpm -C ./e2e run case",
Expand Down
52 changes: 51 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,41 @@ function config({ location, pkgJson, verboseMode }) {
],
plugins: curPlugins
};
},
bundled: (compress) => {
// ES module format with no external dependencies (bundled)
const bundledFile = path.join(location, "dist", compress ? "bundled.module.min.js" : "bundled.module.js");

const bundledPlugins = Array.from(curPlugins);

if (compress) {
const glslifyPluginIdx = bundledPlugins.findIndex((item) => item === glslPlugin);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] 这里依赖 findIndex(...) 命中 glslPlugin,但没有对 -1 做保护;如果后续插件列表调整导致引用不匹配,splice(-1, 1, ...) 会误替换最后一个插件。建议加显式判断(找不到就 push 或抛错),避免静默生成错误配置。

bundledPlugins.splice(
glslifyPluginIdx,
1,
glsl({
include: [/\.(glsl|gs)$/],
compress: true
})
);
bundledPlugins.push(minify({
sourceMap: true,
module: true // Indicate this is an ES module
}));
}

return {
input,
external: [], // No external dependencies - bundle everything
output: [
{
file: bundledFile,
format: "es",
sourcemap: true
}
],
plugins: bundledPlugins
};
}
};
}
Expand All @@ -161,6 +196,9 @@ switch (BUILD_TYPE) {
case "MODULE":
promises.push(...getModule());
break;
case "BUNDLED":
promises.push(...getBundled());
break;
case "ALL":
promises.push(...getAll());
break;
Expand Down Expand Up @@ -189,8 +227,20 @@ function getModule() {
return configs.map((config) => makeRollupConfig({ ...config, type: "module" }));
}

function getBundled() {
// Only build bundled version for @galacean/engine package
const galaceanConfig = pkgs.find((pkg) => pkg.pkgJson.name === "@galacean/engine");
if (galaceanConfig) {
return [
makeRollupConfig({ ...galaceanConfig, type: "bundled", compress: false }),
makeRollupConfig({ ...galaceanConfig, type: "bundled", compress: true })
];
}
return [];
}

function getAll() {
return [...getModule(), ...getUMD()];
return [...getModule(), ...getUMD(), ...getBundled()];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] getAll() 这里把 bundled 也并入了 ALL,会让 release/typedoc 这类依赖 b:all 的流程新增两次打包(bundled + bundled.min)。如果这是预期语义建议在 PR 描述里明确;如果只是提供可选产物,建议保持 b:bundled 独立触发,避免默认流程时间和资源开销上涨。

}

export default Promise.all(promises);
Loading