1
1
import path from 'node:path'
2
2
import process from 'node:process'
3
3
import { fileURLToPath } from 'node:url'
4
- import {
5
- build as rolldownBuild ,
6
- type InputOptions ,
7
- type OutputOptions ,
8
- } from 'rolldown'
4
+ import { build as rolldownBuild , type OutputOptions } from 'rolldown'
9
5
import { transformPlugin } from 'rolldown/experimental'
10
6
import { IsolatedDecl } from 'unplugin-isolated-decl'
11
7
import { Unused } from 'unplugin-unused'
@@ -17,6 +13,7 @@ import { getShimsInject } from './features/shims'
17
13
import { shortcuts } from './features/shortcuts'
18
14
import { watchBuild } from './features/watch'
19
15
import {
16
+ mergeUserOptions ,
20
17
resolveOptions ,
21
18
type Config ,
22
19
type Options ,
@@ -118,36 +115,37 @@ export async function buildSingle(
118
115
119
116
await Promise . all (
120
117
format . map ( async ( format ) => {
121
- const inputOptions : InputOptions = {
122
- input : entry ,
123
- external ,
124
- resolve : { alias } ,
125
- treeshake ,
126
- platform ,
127
- define ,
128
- plugins ,
129
- ... resolved . inputOptions ,
130
- inject : {
131
- ...( shims && getShimsInject ( format , platform ) ) ,
132
- ... resolved . inputOptions ?. inject ,
118
+ const inputOptions = await mergeUserOptions (
119
+ {
120
+ input : entry ,
121
+ external ,
122
+ resolve : { alias } ,
123
+ treeshake ,
124
+ platform ,
125
+ define ,
126
+ plugins ,
127
+ inject : {
128
+ ...( shims && getShimsInject ( format , platform ) ) ,
129
+ } ,
133
130
} ,
134
- }
131
+ resolved . inputOptions ,
132
+ [ format ] ,
133
+ )
135
134
136
135
const extension = resolveOutputExtension ( pkg , format )
137
- let outputOptions : OutputOptions = {
138
- format,
139
- name : resolved . globalName ,
140
- sourcemap,
141
- dir : outDir ,
142
- minify,
143
- entryFileNames : `[name].${ extension } ` ,
144
- chunkFileNames : `[name]-[hash].${ extension } ` ,
145
- }
146
- const userOutputOptions =
147
- typeof resolved . outputOptions === 'function'
148
- ? await resolved . outputOptions ( outputOptions , format )
149
- : resolved . outputOptions
150
- outputOptions = { ...outputOptions , ...userOutputOptions }
136
+ const outputOptions : OutputOptions = await mergeUserOptions (
137
+ {
138
+ format,
139
+ name : resolved . globalName ,
140
+ sourcemap,
141
+ dir : outDir ,
142
+ minify,
143
+ entryFileNames : `[name].${ extension } ` ,
144
+ chunkFileNames : `[name]-[hash].${ extension } ` ,
145
+ } ,
146
+ resolved . outputOptions ,
147
+ [ format ] ,
148
+ )
151
149
152
150
await rolldownBuild ( {
153
151
...inputOptions ,
0 commit comments