Skip to content

Commit

Permalink
feat: use rolldown effectively for the optimizer (#70)
Browse files Browse the repository at this point in the history
* feat: use oxc for the scanner and pass non-js files directly to rolldown
* feat: use builtin transform for optimizer rolldown
* feat: use filter for the plugins for optimizer
  • Loading branch information
sapphi-red authored Nov 29, 2024
1 parent 48f59ce commit 5a51f96
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 191 deletions.
19 changes: 2 additions & 17 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { transformWithEsbuild } from '../plugins/esbuild'
import { METADATA_FILENAME } from '../constants'
import { isWindows } from '../../shared/utils'
import type { Environment } from '../environment'
import { transformWithOxc } from '../plugins/oxc'
import { ScanEnvironment, scanImports } from './scan'
import { createOptimizeDepsIncludeResolver, expandGlobIds } from './resolve'
import {
Expand Down Expand Up @@ -767,22 +766,7 @@ async function prepareRolldownOptimizerRun(
if (external.length) {
plugins.push(rolldownCjsExternalPlugin(external, platform))
}
plugins.push(rolldownDepPlugin(environment, flatIdDeps, external))
plugins.push({
name: 'optimizer-transform',
async transform(code, id) {
if (/\.(?:m?[jt]s|[jt]sx)$/.test(id)) {
const result = await transformWithOxc(this, code, id, {
sourcemap: true,
lang: jsxLoader && /\.js$/.test(id) ? 'jsx' : undefined,
})
return {
code: result.code,
map: result.map,
}
}
},
})
plugins.push(...rolldownDepPlugin(environment, flatIdDeps, external))

let canceled = false
async function build() {
Expand All @@ -804,6 +788,7 @@ async function prepareRolldownOptimizerRun(
moduleTypes: {
'.css': 'js',
...rollupOptions.moduleTypes,
...(jsxLoader ? { '.js': 'jsx' } : {}),
},
})
if (canceled) {
Expand Down
Loading

0 comments on commit 5a51f96

Please sign in to comment.