Skip to content

Commit

Permalink
feat: use rolldown minify (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: Yury <[email protected]>
  • Loading branch information
sapphi-red and YurySolovyov committed Dec 26, 2024
1 parent 0ccb934 commit 16218c9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ export interface BuildEnvironmentOptions {
sourcemap?: boolean | 'inline' | 'hidden'
/**
* Set to `false` to disable minification, or specify the minifier to use.
* Available options are 'terser' or 'esbuild'.
* @default 'esbuild'
* Available options are 'terser' or 'esbuild' or 'oxc'.
* @default 'oxc'
*/
minify?: boolean | 'terser' | 'esbuild'
minify?: boolean | 'terser' | 'esbuild' | 'oxc'
/**
* Options for terser
* https://terser.org/docs/api-reference#minify-options
Expand Down Expand Up @@ -415,7 +415,7 @@ export function resolveBuildEnvironmentOptions(
{
...buildEnvironmentOptionsDefaults,
cssCodeSplit: !raw.lib,
minify: consumer === 'server' ? false : 'esbuild',
minify: consumer === 'server' ? false : 'oxc',
rollupOptions: {
platform: consumer === 'server' ? 'node' : 'browser',
},
Expand All @@ -435,7 +435,7 @@ export function resolveBuildEnvironmentOptions(
if ((merged.minify as string) === 'false') {
merged.minify = false
} else if (merged.minify === true) {
merged.minify = 'esbuild'
merged.minify = 'oxc'
}

const defaultModulePreload = {
Expand Down Expand Up @@ -766,6 +766,7 @@ async function buildEnvironment(
output.format === 'iife' ||
(isSsrTargetWebworkerEnvironment &&
(typeof input === 'string' || Object.keys(input).length === 1)),
minify: options.minify === 'oxc',
...output,
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ async function bundleWorkerEntry(
config.build.assetsDir,
'[name]-[hash].[ext]',
),
minify: config.build.minify === 'oxc',
...workerConfig,
format,
sourcemap: config.build.sourcemap,
Expand Down
2 changes: 1 addition & 1 deletion playground/css-codesplit/__tests__/css-codesplit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe.runIf(isBuild)('build', () => {
expect(sharedCSSWithJSChunk).toMatch(`/* empty css`)
// there are functions and modules in the src code that should be tree-shaken
expect(sharedCSSWithJSChunk).not.toMatch('function')
expect(sharedCSSWithJSChunk).not.toMatch(/import(?!".\/modulepreload)/)
expect(sharedCSSWithJSChunk).not.toMatch(/import(?!\s*".\/modulepreload)/)
})

test('should generate correct manifest', async () => {
Expand Down
2 changes: 1 addition & 1 deletion playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe.runIf(isBuild)('build tests', () => {
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
{
"ignoreList": [],
"mappings": ";4jCAAA,OAAO,6BAAuB,wBAE9B,QAAQ,IAAI",
"mappings": ";ypCAAA,OAAO,6BAAuB,wBAE9B,QAAQ,IAAI,wBAAuB",
"sources": [
"../../after-preload-dynamic.js",
],
Expand Down
4 changes: 2 additions & 2 deletions playground/worker/__tests__/es/worker-es.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe.runIf(isBuild)('build', () => {
)

// worker should have all imports resolved and no exports
expect(workerContent).not.toMatch(/import[^.]/)
expect(workerContent).not.toMatch(/import\s*["(]/)
expect(workerContent).not.toMatch(/\bexport\b/)
// chunk
expect(content).toMatch(`new Worker("/es/assets`)
Expand All @@ -113,7 +113,7 @@ describe.runIf(isBuild)('build', () => {
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
expect(content).toMatch(`self.Blob`)
expect(content).toMatch(
/try\{if\(\w+=\w+&&\(self\.URL\|\|self\.webkitURL\)\.createObjectURL\(\w+\),!\w+\)throw""/,
/try\{\w+=\w+&&\(self\.URL\|\|self\.webkitURL\)\.createObjectURL\(\w+\)[;\w()!]+throw\s*""/,
)
// inlined shared worker
expect(content).toMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe.runIf(isBuild)('build', () => {
)

// worker should have all imports resolved and no exports
expect(workerContent).not.toMatch(/import(?!\.)/) // accept import.meta.url
expect(workerContent).not.toMatch(/import\s*["(]/)
expect(workerContent).not.toMatch(/\bexport\b/)
// chunk
expect(content).toMatch(`new Worker(""+new URL("../worker-entries/`)
Expand Down

0 comments on commit 16218c9

Please sign in to comment.