-
-
Notifications
You must be signed in to change notification settings - Fork 401
feat: add bundled ESM output #2766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] 这里依赖 |
||
| 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 | ||
| }; | ||
| } | ||
| }; | ||
| } | ||
|
|
@@ -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; | ||
|
|
@@ -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()]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] |
||
| } | ||
|
|
||
| export default Promise.all(promises); | ||
There was a problem hiding this comment.
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 阶段被拦住。