( environment: Environment, chunkMetadataMap: ChunkMetadataMap, )
| 584 | } |
| 585 | |
| 586 | export function resolveRolldownOptions( |
| 587 | environment: Environment, |
| 588 | chunkMetadataMap: ChunkMetadataMap, |
| 589 | ): RolldownOptions { |
| 590 | const { root, packageCache, base, build: options } = environment.config |
| 591 | const libOptions = options.lib |
| 592 | const { logger } = environment |
| 593 | const ssr = environment.config.consumer === 'server' |
| 594 | |
| 595 | const resolve = (p: string) => path.resolve(root, p) |
| 596 | const input = libOptions |
| 597 | ? options.rolldownOptions.input || |
| 598 | (typeof libOptions.entry === 'string' |
| 599 | ? resolve(libOptions.entry) |
| 600 | : Array.isArray(libOptions.entry) |
| 601 | ? libOptions.entry.map(resolve) |
| 602 | : Object.fromEntries( |
| 603 | Object.entries(libOptions.entry).map(([alias, file]) => [ |
| 604 | alias, |
| 605 | resolve(file), |
| 606 | ]), |
| 607 | )) |
| 608 | : typeof options.ssr === 'string' |
| 609 | ? resolve(options.ssr) |
| 610 | : options.rolldownOptions.input || resolve('index.html') |
| 611 | |
| 612 | if (ssr && typeof input === 'string' && input.endsWith('.html')) { |
| 613 | throw new Error( |
| 614 | `rolldownOptions.input should not be an html file when building for SSR. ` + |
| 615 | `Please specify a dedicated SSR entry.`, |
| 616 | ) |
| 617 | } |
| 618 | if (options.cssCodeSplit === false) { |
| 619 | const inputs = |
| 620 | typeof input === 'string' |
| 621 | ? [input] |
| 622 | : Array.isArray(input) |
| 623 | ? input |
| 624 | : Object.values(input) |
| 625 | if (inputs.some((input) => input.endsWith('.css'))) { |
| 626 | throw new Error( |
| 627 | `When "build.cssCodeSplit: false" is set, "rolldownOptions.input" should not include CSS files.`, |
| 628 | ) |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | const outDir = resolve(options.outDir) |
| 633 | |
| 634 | // inject environment and ssr arg to plugin load/transform hooks |
| 635 | const plugins = environment.plugins.map((p) => |
| 636 | injectEnvironmentToHooks(environment, chunkMetadataMap, p), |
| 637 | ) |
| 638 | |
| 639 | const rolldownOptions: RolldownOptions = { |
| 640 | preserveEntrySignatures: ssr |
| 641 | ? 'allow-extension' |
| 642 | : libOptions |
| 643 | ? 'strict' |
no test coverage detected