-
-
Notifications
You must be signed in to change notification settings - Fork 828
feat: rolldownConfig #3887
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
Merged
Merged
feat: rolldownConfig #3887
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
10e2367
feat: rolldownConfig
pi0 1005d89
Merge branch 'main' into feat/rolldown-config
pi0 5860fa5
Merge branch 'main' into feat/rolldown-config
pi0 22e4e86
wip
pi0 bc7b395
Merge branch 'main' into feat/rolldown-config
pi0 f852ecd
update
pi0 78b91f4
remove unused import
pi0 998f738
fix plugins
pi0 fb5f6e4
lazy import rollup-specific plugins
pi0 27a3846
fix double defaults
pi0 2195e02
update msg
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { defu } from "defu"; | ||
| import { baseBuildConfig, type BaseBuildConfig } from "../config.ts"; | ||
| import { getChunkName, libChunkName, NODE_MODULES_RE } from "../chunks.ts"; | ||
| import { baseBuildPlugins } from "../plugins.ts"; | ||
|
|
||
| import type { RolldownConfig, RollupConfig } from "nitro/types"; | ||
| import type { Plugin as RollupPlugin } from "rollup"; | ||
| import type { NitroPluginContext } from "./types.ts"; | ||
|
|
||
| export const getBundlerConfig = async ( | ||
| ctx: NitroPluginContext | ||
| ): Promise<{ | ||
| base: BaseBuildConfig; | ||
| rollupConfig?: RollupConfig; | ||
| rolldownConfig?: RolldownConfig; | ||
| }> => { | ||
| const nitro = ctx.nitro!; | ||
| const base = baseBuildConfig(nitro); | ||
|
|
||
| const commonConfig = { | ||
| input: nitro.options.entry, | ||
| external: [...base.env.external], | ||
| plugins: [...(await baseBuildPlugins(nitro, base))].filter( | ||
| Boolean | ||
| ) as RollupPlugin[], | ||
| treeshake: { | ||
| moduleSideEffects(id) { | ||
| return nitro.options.moduleSideEffects.some((p) => id.startsWith(p)); | ||
| }, | ||
| }, | ||
| onwarn(warning, warn) { | ||
| if (!base.ignoreWarningCodes.has(warning.code || "")) { | ||
| warn(warning); | ||
| } | ||
| }, | ||
| output: { | ||
| dir: nitro.options.output.serverDir, | ||
| format: "esm", | ||
| entryFileNames: "index.mjs", | ||
| chunkFileNames: (chunk: { name: string; moduleIds: string[] }) => | ||
| getChunkName(chunk, nitro), | ||
| inlineDynamicImports: nitro.options.inlineDynamicImports, | ||
| sourcemapIgnoreList: (id) => id.includes("node_modules"), | ||
| }, | ||
| } satisfies RollupConfig & RolldownConfig; | ||
|
|
||
| if (ctx._isRolldown) { | ||
| // Rolldown | ||
| const rolldownConfig = { | ||
| transform: { | ||
| inject: base.env.inject as Record<string, string>, | ||
| }, | ||
| output: { | ||
| codeSplitting: { | ||
| groups: [ | ||
| { | ||
| test: NODE_MODULES_RE, | ||
| name: (id: string) => libChunkName(id), | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| } satisfies RolldownConfig; | ||
|
|
||
| return { | ||
| base, | ||
| rollupConfig: undefined, | ||
| rolldownConfig: defu( | ||
| rolldownConfig, | ||
| nitro.options.rolldownConfig, | ||
| nitro.options.rollupConfig as RolldownConfig, // Added for backward compatibility | ||
| commonConfig satisfies RolldownConfig | ||
| ), | ||
| }; | ||
| } else { | ||
| // Rollup | ||
| const inject = ( | ||
| (await import("@rollup/plugin-inject")) as unknown as typeof import("@rollup/plugin-inject") | ||
| ).default; | ||
| const alias = ( | ||
| (await import("@rollup/plugin-alias")) as unknown as typeof import("@rollup/plugin-alias") | ||
| ).default; | ||
|
|
||
| const rollupConfig: RollupConfig = { | ||
| plugins: [inject(base.env.inject), alias({ entries: base.aliases })], | ||
| output: { | ||
| sourcemapExcludeSources: true, | ||
| generatedCode: { | ||
| constBindings: true, | ||
| }, | ||
| manualChunks(id: string) { | ||
| if (NODE_MODULES_RE.test(id)) { | ||
| return libChunkName(id); | ||
| } | ||
| }, | ||
| }, | ||
| } satisfies RollupConfig; | ||
|
|
||
| return { | ||
| base, | ||
| rolldownConfig: undefined, | ||
| rollupConfig: defu( | ||
| rollupConfig, | ||
| nitro.options.rolldownConfig as RollupConfig, // Added for backward compatibility | ||
| nitro.options.rollupConfig, | ||
| commonConfig | ||
| ), | ||
| }; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.