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
54 changes: 54 additions & 0 deletions packages/vite/src/node/__tests__/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,60 @@ describe('resolveBuildOutputs', () => {
)
})
})

describe('output minify and comments resolution in resolveRolldownOptions', () => {
const buildProjectRoot = resolve(dirname, 'packages/build-project')

test('merges a partial output.minify object with the lib defaults', async () => {
const builder = await createBuilder({
root: buildProjectRoot,
logLevel: 'silent',
build: {
minify: 'oxc',
lib: { ...baseLibOptions, formats: ['es'] },
rolldownOptions: {
output: {
minify: { mangle: { keepNames: true } },
},
},
},
})
const options = resolveRolldownOptions(
builder.environments.client,
new ChunkMetadataMap(),
)
const outputs = options.output!
const output = Array.isArray(outputs) ? outputs[0] : outputs
expect(output.minify).toStrictEqual({
compress: true,
mangle: { keepNames: true },
codegen: false,
})
})

test('keeps an explicit boolean output.minify untouched', async () => {
const builder = await createBuilder({
root: buildProjectRoot,
logLevel: 'silent',
build: {
minify: 'oxc',
lib: { ...baseLibOptions, formats: ['es'] },
rolldownOptions: {
output: {
minify: false,
},
},
},
})
const options = resolveRolldownOptions(
builder.environments.client,
new ChunkMetadataMap(),
)
const outputs = options.output!
const output = Array.isArray(outputs) ? outputs[0] : outputs
expect(output.minify).toBe(false)
})
})
})

describe('resolveLibFilename', () => {
Expand Down
35 changes: 21 additions & 14 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,20 @@ export function resolveRolldownOptions(
findNearestPackageData(root, packageCache)?.data.type,
)
: 'js'
const resolvedMinify =
options.minify === 'oxc'
? libOptions && (format === 'es' || format === 'esm')
? {
compress: true,
mangle: true,
// Do not minify whitespace for ES lib output since that would remove
// pure annotations and break tree-shaking
codegen: false,
}
: true
: options.minify === false
? 'dce-only'
: false
return {
dir: outDir,
// Default format is 'es' for regular and for SSR builds
Expand Down Expand Up @@ -786,22 +800,15 @@ export function resolveRolldownOptions(
(typeof input === 'string' || Object.keys(input).length === 1))
? false
: undefined),
minify:
options.minify === 'oxc'
? libOptions && (format === 'es' || format === 'esm')
? {
compress: true,
mangle: true,
// Do not minify whitespace for ES lib output since that would remove
// pure annotations and break tree-shaking
codegen: false,
}
: true
: options.minify === false
? 'dce-only'
: false,
topLevelVar: true,
...output,
minify:
output.minify === undefined
? resolvedMinify
: typeof output.minify === 'object' &&
typeof resolvedMinify === 'object'
? { ...resolvedMinify, ...output.minify }
: output.minify,
comments:
typeof output.comments === 'boolean'
? output.comments
Expand Down
Loading