Skip to content

Commit 6681f0a

Browse files
feat: use rolldown builtin OXC minifier by default
Co-authored-by: Yury <[email protected]>
1 parent 1dc7cb4 commit 6681f0a

File tree

13 files changed

+87
-76
lines changed

13 files changed

+87
-76
lines changed

packages/vite/src/node/__tests__/build.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ test.for([true, false])(
861861
([client, ssr, custom1, custom2] as RolldownOutput[]).map(
862862
(o) => o.output[0].code.split('\n').length,
863863
),
864-
).toEqual([2, 5, 2, 5])
864+
).toEqual([1, 5, 1, 5])
865865
},
866866
)
867867

packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/__snapshots__/modulePreloadPolyfill.spec.ts.snap

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ exports[`load > doesn't load modulepreload polyfill when format is cjs 1`] = `
77

88
exports[`load > loads modulepreload polyfill 1`] = `
99
"(function polyfill() {
10-
const relList = document.createElement("link").relList;
11-
if (relList && relList.supports && relList.supports("modulepreload")) return;
12-
for (const link of document.querySelectorAll('link[rel="modulepreload"]')) processPreload(link);
13-
new MutationObserver((mutations) => {
14-
for (const mutation of mutations) {
15-
if (mutation.type !== "childList") continue;
16-
for (const node of mutation.addedNodes) if (node.tagName === "LINK" && node.rel === "modulepreload") processPreload(node);
17-
}
18-
}).observe(document, {
19-
childList: true,
20-
subtree: true
21-
});
22-
function getFetchOpts(link) {
23-
const fetchOpts = {};
24-
if (link.integrity) fetchOpts.integrity = link.integrity;
25-
if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
26-
if (link.crossOrigin === "use-credentials") fetchOpts.credentials = "include";
27-
else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
28-
else fetchOpts.credentials = "same-origin";
29-
return fetchOpts;
30-
}
31-
function processPreload(link) {
32-
if (link.ep) return;
33-
link.ep = true;
34-
const fetchOpts = getFetchOpts(link);
35-
fetch(link.href, fetchOpts);
36-
}
10+
const relList = document.createElement("link").relList;
11+
if (relList && relList.supports && relList.supports("modulepreload")) return;
12+
for (const link of document.querySelectorAll("link[rel=\\"modulepreload\\"]")) processPreload(link);
13+
new MutationObserver((mutations) => {
14+
for (const mutation of mutations) {
15+
if (mutation.type !== "childList") continue;
16+
for (const node of mutation.addedNodes) if (node.tagName === "LINK" && node.rel === "modulepreload") processPreload(node);
17+
}
18+
}).observe(document, {
19+
childList: true,
20+
subtree: true
21+
});
22+
function getFetchOpts(link) {
23+
const fetchOpts = {};
24+
if (link.integrity) fetchOpts.integrity = link.integrity;
25+
if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
26+
if (link.crossOrigin === "use-credentials") fetchOpts.credentials = "include";
27+
else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
28+
else fetchOpts.credentials = "same-origin";
29+
return fetchOpts;
30+
}
31+
function processPreload(link) {
32+
if (link.ep) return;
33+
link.ep = true;
34+
const fetchOpts = getFetchOpts(link);
35+
fetch(link.href, fetchOpts);
36+
}
3737
})();
3838
"
3939
`;

packages/vite/src/node/build.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ export interface BuildEnvironmentOptions {
172172
sourcemap?: boolean | 'inline' | 'hidden'
173173
/**
174174
* Set to `false` to disable minification, or specify the minifier to use.
175-
* Available options are 'terser' or 'esbuild'.
176-
* @default 'esbuild'
175+
* Available options are 'oxc' or 'terser' or 'esbuild'.
176+
* @default 'oxc'
177177
*/
178-
minify?: boolean | 'terser' | 'esbuild'
178+
minify?: boolean | 'oxc' | 'terser' | 'esbuild'
179179
/**
180180
* Options for terser
181181
* https://terser.org/docs/api-reference#minify-options
@@ -419,7 +419,7 @@ export function resolveBuildEnvironmentOptions(
419419
{
420420
...buildEnvironmentOptionsDefaults,
421421
cssCodeSplit: !raw.lib,
422-
minify: consumer === 'server' ? false : 'esbuild',
422+
minify: consumer === 'server' ? false : 'oxc',
423423
rollupOptions: {
424424
platform: consumer === 'server' ? 'node' : 'browser',
425425
},
@@ -439,7 +439,7 @@ export function resolveBuildEnvironmentOptions(
439439
if ((merged.minify as string) === 'false') {
440440
merged.minify = false
441441
} else if (merged.minify === true) {
442-
merged.minify = 'esbuild'
442+
merged.minify = 'oxc'
443443
}
444444

445445
const defaultModulePreload = {
@@ -758,7 +758,12 @@ async function buildEnvironment(
758758
output.format === 'iife' ||
759759
(isSsrTargetWebworkerEnvironment &&
760760
(typeof input === 'string' || Object.keys(input).length === 1)),
761-
minify: false,
761+
minify:
762+
options.minify === 'oxc'
763+
? true
764+
: options.minify === false
765+
? 'dce-only'
766+
: false,
762767
...output,
763768
}
764769
}

packages/vite/src/node/plugins/worker.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ async function bundleWorkerEntry(
133133
config.build.assetsDir,
134134
'[name]-[hash].[ext]',
135135
),
136+
minify:
137+
config.build.minify === 'oxc'
138+
? true
139+
: config.build.minify === false
140+
? 'dce-only'
141+
: undefined,
136142
...workerConfig,
137143
format,
138144
sourcemap: config.build.sourcemap,

playground/js-sourcemap/__tests__/js-sourcemap.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe.runIf(isBuild)('build tests', () => {
143143
{
144144
"debugId": "00000000-0000-0000-0000-000000000000",
145145
"ignoreList": [],
146-
"mappings": ";4jCAAA,OAAO,6BAAuB,wBAE9B,QAAQ,IAAI",
146+
"mappings": ";sjCAEA,MAFA,OAAO,6BAAuB,wBAE9B,QAAQ,IAAI,wBAAuB",
147147
"sources": [
148148
"../../after-preload-dynamic.js",
149149
],
@@ -181,7 +181,7 @@ describe.runIf(isBuild)('build tests', () => {
181181
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
182182
{
183183
"debugId": "00000000-0000-0000-0000-000000000000",
184-
"mappings": "qBAEA,SAAS,GAAO,CACd,EAAA,CACF,CAEA,SAAS,GAAY,CAEnB,QAAQ,MAAM,qBAAsB,CAAA,CACtC,CAEA,EAAA",
184+
"mappings": "qBAEA,SAAS,GAAO,CACd,GAAU,AACZ,CAEA,SAAS,GAAY,CAEnB,QAAQ,MAAM,qBAAsB,EAAkB,AACxD,CAEA,GAAK",
185185
"sources": [
186186
"../../with-define-object.ts",
187187
],

playground/lib/__tests__/lib.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe.runIf(isBuild)('build', () => {
2424
// esbuild helpers are injected inside of the UMD wrapper
2525
expect(code).toMatch(/^\(function\(/)
2626
expect(noMinifyCode).toMatch(
27-
/^\(function\(global.+?"use strict";\/\*[^*]*\*\/\s*var.+?function\smyLib\(/s,
27+
/^\(function\(global.+?"use strict";\s*var.+?function\smyLib\(/s,
2828
)
2929
expect(namedCode).toMatch(/^\(function\(/)
3030
})
@@ -51,7 +51,7 @@ describe.runIf(isBuild)('build', () => {
5151
'dist/helpers-injection/my-lib-custom-filename.iife.js',
5252
)
5353
expect(code).toMatch(
54-
`'"use strict"; return (' + expressionSyntax + ").constructor;"`,
54+
`\\"use strict\\"; return (" + expressionSyntax + ").constructor;"`,
5555
)
5656
})
5757

@@ -64,14 +64,14 @@ describe.runIf(isBuild)('build', () => {
6464
expect(code).not.toMatch('__vitePreload')
6565

6666
// Test that library chunks are hashed
67-
expect(code).toMatch(/await import\("\.\/message-[-\w]{8}.js"\)/)
67+
expect(code).toMatch(/await import\(`\.\/message-[-\w]{8}.js`\)/)
6868
})
6969

7070
test('Library mode does not have any reference to pure CSS chunks', async () => {
7171
const code = readFile('dist/lib/dynamic-import-message.es.mjs')
7272

7373
// Does not import pure CSS chunks and replaced by `Promise.resolve({})` instead
74-
expect(code).not.toMatch(/await import\("\.\/dynamic-[-\w]{8}.js"\)/)
74+
expect(code).not.toMatch(/await import\(`\.\/dynamic-[-\w]{8}.js`\)/)
7575
expect(code).toMatch(/await Promise.resolve\(\{.*\}\)/)
7676
})
7777

playground/minify/__tests__/minify.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test.runIf(isBuild)('no minifySyntax', () => {
1313
const cssFile = files.find((f) => f.endsWith('.css'))
1414
const cssContent = readFile(path.resolve(assetsDir, cssFile))
1515

16-
expect(jsContent).toContain(')console.log("hello world")')
16+
expect(jsContent).toContain('console.log(`hello world`)')
1717
expect(jsContent).not.toContain('/*! explicit comment */')
1818

1919
expect(cssContent).toContain('color:#ff0000')

playground/worker/__tests__/es/worker-es.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ describe.runIf(isBuild)('build', () => {
104104
)
105105

106106
// worker should have all imports resolved and no exports
107-
expect(workerContent).not.toMatch(/import[^.]/)
107+
expect(workerContent).not.toMatch(/import\s*["(]/)
108108
expect(workerContent).not.toMatch(/\bexport\b/)
109109
// chunk
110-
expect(content).toMatch(`new Worker("/es/assets`)
111-
expect(content).toMatch(`new SharedWorker("/es/assets`)
110+
expect(content).toMatch('new Worker(`/es/assets')
111+
expect(content).toMatch('new SharedWorker(`/es/assets')
112112
// inlined worker
113113
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
114114
expect(content).toMatch(`self.Blob`)
115115
expect(content).toMatch(
116-
/try\{if\(\w+=\w+&&\(self\.URL\|\|self\.webkitURL\)\.createObjectURL\(\w+\),!\w+\)throw""/,
116+
/try\{if\(\w+=\w+&&\(self\.URL\|\|self\.webkitURL\)\.createObjectURL\(\w+\),!\w+\)throw``/,
117117
)
118118
// inlined shared worker
119119
expect(content).toMatch(
120-
`return new SharedWorker("data:text/javascript;charset=utf-8,"+`,
120+
'return new SharedWorker(`data:text/javascript;charset=utf-8,`+',
121121
)
122122
})
123123

playground/worker/__tests__/iife/worker-iife.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ describe.runIf(isBuild)('build', () => {
9191
)
9292

9393
// worker should have all imports resolved and no exports
94-
expect(workerContent).not.toMatch(`import`)
94+
expect(workerContent).not.toMatch(/import\s*["(]/)
9595
expect(workerContent).not.toMatch(/\bexport\b/)
9696
// chunk
97-
expect(content).toMatch(`new Worker("/iife/assets`)
98-
expect(content).toMatch(`new SharedWorker("/iife/assets`)
97+
expect(content).toMatch('new Worker(`/iife/assets')
98+
expect(content).toMatch('new SharedWorker(`/iife/assets')
9999
// inlined
100100
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
101101
expect(content).toMatch(`self.Blob`)

playground/worker/__tests__/relative-base/worker-relative-base.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ describe.runIf(isBuild)('build', () => {
7575
)
7676

7777
// worker should have all imports resolved and no exports
78-
expect(workerContent).not.toMatch(/import(?!\.)/) // accept import.meta.url
78+
expect(workerContent).not.toMatch(/import\s*["(]/)
7979
expect(workerContent).not.toMatch(/\bexport\b/)
8080
// chunk
81-
expect(content).toMatch(`new Worker(""+new URL("../worker-entries/`)
82-
expect(content).toMatch(`new SharedWorker(""+new URL("../worker-entries/`)
81+
expect(content).toMatch('new Worker(``+new URL(`../worker-entries/')
82+
expect(content).toMatch('new SharedWorker(``+new URL(`../worker-entries/')
8383
// inlined
8484
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
8585
expect(content).toMatch(`self.Blob`)

0 commit comments

Comments
 (0)