Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use Rolldown's watch API #67

Draft
wants to merge 97 commits into
base: rolldown-v6
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
4b310b7
feat: use rolldown in the dep optimizer
sapphi-red Sep 11, 2024
82fea72
feat: use rolldown for build
sapphi-red Sep 12, 2024
4803f6c
chore: skip plugin-legacy build
sapphi-red Sep 12, 2024
cae9de7
chore: skip typecheck for now
sapphi-red Sep 12, 2024
15bdbca
chore: 🤖 add justfile for faster dev
IWANABETHATGUY Aug 15, 2024
6a5c12f
feat: add experimental.enableNativePlugin (#41)
IWANABETHATGUY Sep 10, 2024
d2abb2d
feat: clone class plugins correctly
IWANABETHATGUY Sep 13, 2024
83e64f0
feat: native build plugins (#45) (#46)
IWANABETHATGUY Sep 12, 2024
7607377
perf: reduce pre alias plugin in build mode
IWANABETHATGUY Sep 12, 2024
2917b77
feat: 🎸 add an new option to disable build report
IWANABETHATGUY Sep 13, 2024
88ee06e
feat: support native define
sapphi-red Sep 18, 2024
155fe98
feat: use filter for plugins (#49) (#50) (#51) (#52) (#53)
sapphi-red Sep 18, 2024
34772a5
perf: ⚡️ use default resolver (#56)
IWANABETHATGUY Sep 14, 2024
8c2c27f
fix: 🐛 lint (#58)
IWANABETHATGUY Sep 20, 2024
9ad08d1
chore: bump rolldown
sapphi-red Sep 24, 2024
852c221
chore: skip data uri by load fallback plugin for native data uri hand…
sapphi-red Sep 24, 2024
6a4d274
feat: handle non-relative paths by Vite's resolver for enableNativePl…
sapphi-red Sep 19, 2024
866e97d
chore: remove browser field edge case test
sapphi-red Sep 25, 2024
cf3aa12
chore: use advancedChunks instead of manualChunks
sapphi-red Oct 1, 2024
72b6177
feat: convert `optimizeDeps.esbuildOptions` to `optimizeDeps.rollupOp…
sapphi-red Oct 4, 2024
a5ce12c
fix: optimizeDeps test pass on windows
sapphi-red Oct 9, 2024
c1b13da
chore: make some tests passing
sapphi-red Oct 9, 2024
94cf842
chore: make glob-import test pass with workarounds
sapphi-red Oct 9, 2024
a6873b6
chore: run worker-es tests
sapphi-red Oct 9, 2024
9872f25
fix: use preliminaryFileName for chunkMetadata key
sapphi-red Oct 10, 2024
747f26b
feat: oxc tranformer (#60)
underfin Oct 11, 2024
1a228be
feat: use `onlyRemoveTypeImports`
sapphi-red Oct 11, 2024
cce68ef
chore: enable continuous release under rolldown-vite (#61)
yyx990803 Oct 12, 2024
6e3fd69
feat: environment aware native plugins
sapphi-red Oct 15, 2024
bc223cd
feat: export transformWithOxc (#62)
underfin Oct 17, 2024
c967ea7
feat: add oxc jsxInclude and jsxExclude (#63)
underfin Oct 18, 2024
2e134f1
chore: update some tests that relies on rollup's behavior
sapphi-red Oct 24, 2024
e483ce3
chore: skip environment-react-ssr for now
sapphi-red Oct 24, 2024
45288b4
chore: bump rolldown
sapphi-red Oct 24, 2024
e9ae3e2
chore: skip minifySyntax test as it relies on specific esbuild option
sapphi-red Oct 24, 2024
71c744f
chore: fix type errors
sapphi-red Oct 24, 2024
0043810
chore: skip sideeffects set for HTML scripts for now
sapphi-red Nov 6, 2024
aec2b6e
chore: partial revert "refactor: use `originalFileNames`/`names` (#18…
sapphi-red Nov 6, 2024
396d3af
chore: tweak tests
sapphi-red Nov 6, 2024
94cf27f
chore: bump rolldown
sapphi-red Nov 6, 2024
1f825b9
chore: enable backend-integration test
sapphi-red Nov 6, 2024
448f8e0
chore: skip error message test
sapphi-red Nov 13, 2024
03ef4bc
feat: enable lib mode tests (#64)
sapphi-red Nov 13, 2024
0c0a17b
chore: fix LICENSE
sapphi-red Nov 14, 2024
a5ed542
chore: uncomment things implemented on rolldown now
sapphi-red Nov 18, 2024
1c77f54
chore: enable html sideeffects test
sapphi-red Nov 18, 2024
8f8c69d
chore: reduce diff
sapphi-red Nov 18, 2024
59c8b5b
feat: use native Vite resolver (#65)
sapphi-red Nov 19, 2024
04a742c
chore: add workaround and make environment-react-ssr playground pass
sapphi-red Nov 21, 2024
067347d
chore: add comment
sapphi-red Nov 21, 2024
bff6200
chore: fix oxc option convertion and reduce warnings
sapphi-red Nov 22, 2024
64ba053
chore: bump rolldown
sapphi-red Nov 25, 2024
cc6c2e0
chore: update snapshot
sapphi-red Nov 25, 2024
6f6bb59
chore: fix for new vite resolve plugin
sapphi-red Nov 25, 2024
fb67381
feat: use native plugin for create id resolver (#68)
sapphi-red Nov 25, 2024
b392159
chore: bump rolldown
sapphi-red Nov 28, 2024
f4bc379
chore: fix for the latest rolldown
sapphi-red Nov 28, 2024
8f637cf
chore: enable modulepreload unit test
sapphi-red Nov 28, 2024
7c8a9ee
chore: bump rolldown
sapphi-red Nov 29, 2024
68e6581
chore: set platform option and remove workaround in environment-react…
sapphi-red Nov 29, 2024
4753f60
chore: update some tests that relies on rollup's behavior
sapphi-red Nov 29, 2024
48f59ce
feat: use rolldown for config loader (#69)
sapphi-red Nov 29, 2024
5a51f96
feat: use rolldown effectively for the optimizer (#70)
sapphi-red Nov 29, 2024
4e75b7f
feat: use oxc for non-native define plugin (#71)
sapphi-red Dec 3, 2024
d437a93
feat: use lightningcss by default for cssMinify (#72)
sapphi-red Dec 3, 2024
135a44a
chore: reduce oxc not supported warnings
sapphi-red Dec 3, 2024
6ff7d2e
feat: use rolldown minify (#73)
sapphi-red Dec 4, 2024
55b487d
fix: isolate `chunk.viteMetadata` values for each build (#74)
hi-ogawa Dec 6, 2024
cf0154f
perf: do less on js side for optimizer (#76)
sapphi-red Dec 10, 2024
36c73dd
chore: bump rolldown
sapphi-red Dec 11, 2024
14189d9
chore: handle oxc errors
sapphi-red Dec 11, 2024
95bce64
chore: change for latest native vite resolver plugin
sapphi-red Dec 6, 2024
ad46448
chore: getCombinedSourcemap is now supported
sapphi-red Dec 6, 2024
23bf08b
chore: set keepNames
sapphi-red Dec 6, 2024
ae4c1f7
chore: update sourcemap snapshot
sapphi-red Dec 11, 2024
618dcb1
chore: enable some define tests
sapphi-red Dec 11, 2024
b3b42f8
chore: change for latest native json plugin
sapphi-red Dec 11, 2024
c8677df
chore: update modulePreloadPolyfill snapshot
sapphi-red Dec 11, 2024
89b1191
Revert "chore: partial revert "refactor: use `originalFileNames`/`nam…
sapphi-red Dec 11, 2024
cfdc709
chore: reduce diff for Sourcemap::toUrl/Sourcemap::toString
sapphi-red Dec 11, 2024
f4c3629
chore: make external test pass by manually polyfilling require
sapphi-red Dec 11, 2024
f328a00
chore: remove workaround
sapphi-red Dec 11, 2024
7c66129
feat: use oxc for lowering (#77)
sapphi-red Dec 12, 2024
d97ef9e
feat: make esbuild optional peer dep (#78)
sapphi-red Dec 12, 2024
ebd8db5
fix(css): inline css insert for single quote `use strict` (#79)
underfin Dec 16, 2024
83e86ae
chore: bump rolldown
sapphi-red Dec 16, 2024
fd4392e
chore: apply https://github.com/vitejs/vite/pull/18969
sapphi-red Dec 16, 2024
d49efd5
chore: bump rolldown
sapphi-red Dec 19, 2024
3f8b01f
chore: update for oxc.jsx type change
sapphi-red Dec 19, 2024
a248bb1
chore: update for PluginContext type change
sapphi-red Dec 19, 2024
fa40dbc
fix: return transformed content as `moduleType: 'js'`
sapphi-red Dec 20, 2024
b165069
feat: use setPublicClassFields for useDefineForClassFields support
sapphi-red Dec 20, 2024
84b75a3
fix: set `onlyRemoveTypeImports: false` by default
sapphi-red Dec 20, 2024
0684f20
feat: use Rolldown's watch API
sapphi-red Nov 18, 2024
7d2b36e
chore: remove wait
sapphi-red Nov 21, 2024
f285485
chore: remove chokidar options and add TODOs
sapphi-red Dec 20, 2024
1089317
chore: tweak types
sapphi-red Dec 20, 2024
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
Prev Previous commit
Next Next commit
feat: use rolldown for config loader (#69)
sapphi-red authored Nov 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 48f59ce06725e4cebef6ba038acc76e3f339becc
2 changes: 1 addition & 1 deletion docs/_data/blog.data.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ interface Post {
}

declare const data: Post[]
export { data }
export { type data }

export default createContentLoader('blog/*.md', {
// excerpt: true,
184 changes: 107 additions & 77 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ import { performance } from 'node:perf_hooks'
import { builtinModules, createRequire } from 'node:module'
import colors from 'picocolors'
import type { Alias, AliasOptions } from 'dep-types/alias'
import { build } from 'esbuild'
import type { RollupOptions } from 'rolldown'
import { rolldown } from 'rolldown'
import type { OutputChunk, RollupOptions } from 'rolldown'
import picomatch from 'picomatch'
import type { AnymatchFn } from '../types/anymatch'
import { withTrailingSlash } from '../shared/utils'
@@ -1858,73 +1858,67 @@ async function bundleConfigFile(
const dirnameVarName = '__vite_injected_original_dirname'
const filenameVarName = '__vite_injected_original_filename'
const importMetaUrlVarName = '__vite_injected_original_import_meta_url'
const result = await build({
absWorkingDir: process.cwd(),
entryPoints: [fileName],
write: false,
target: [`node${process.versions.node}`],

const bundle = await rolldown({
input: fileName,
// target: [`node${process.versions.node}`],
platform: 'node',
bundle: true,
format: isESM ? 'esm' : 'cjs',
mainFields: ['main'],
sourcemap: 'inline',
metafile: true,
resolve: {
mainFields: ['main'],
},
define: {
__dirname: dirnameVarName,
__filename: filenameVarName,
'import.meta.url': importMetaUrlVarName,
'import.meta.dirname': dirnameVarName,
'import.meta.filename': filenameVarName,
},
// disable treeshake to include files that is not sideeffectful to `moduleIds`
treeshake: false,
plugins: [
{
name: 'externalize-deps',
setup(build) {
const packageCache = new Map()
const resolveByViteResolver = (
id: string,
importer: string,
isRequire: boolean,
) => {
return tryNodeResolve(id, importer, {
root: path.dirname(fileName),
isBuild: true,
isProduction: true,
preferRelative: false,
tryIndex: true,
mainFields: [],
conditions: [
'node',
...(isModuleSyncConditionEnabled ? ['module-sync'] : []),
],
externalConditions: [],
external: [],
noExternal: [],
dedupe: [],
extensions: configDefaults.resolve.extensions,
preserveSymlinks: false,
packageCache,
isRequire,
})?.id
}

// externalize bare imports
build.onResolve(
{ filter: /^[^.].*/ },
async ({ path: id, importer, kind }) => {
if (
kind === 'entry-point' ||
path.isAbsolute(id) ||
isNodeBuiltin(id)
) {
(() => {
const packageCache = new Map()
const resolveByViteResolver = (
id: string,
importer: string,
isRequire: boolean,
) => {
return tryNodeResolve(id, importer, {
root: path.dirname(fileName),
isBuild: true,
isProduction: true,
preferRelative: false,
tryIndex: true,
mainFields: [],
conditions: [
'node',
...(isModuleSyncConditionEnabled ? ['module-sync'] : []),
],
externalConditions: [],
external: [],
noExternal: [],
dedupe: [],
extensions: configDefaults.resolve.extensions,
preserveSymlinks: false,
packageCache,
isRequire,
})?.id
}

return {
name: 'externalize-deps',
resolveId: {
filter: { id: /^[^.].*/ },
async handler(id, importer, { kind }) {
if (!importer || path.isAbsolute(id) || isNodeBuiltin(id)) {
return
}

// With the `isNodeBuiltin` check above, this check captures if the builtin is a
// non-node built-in, which esbuild doesn't know how to handle. In that case, we
// externalize it so the non-node runtime handles it instead.
if (isBuiltin(id)) {
return { external: true }
return { id, external: true }
}

const isImport = isESM || kind === 'dynamic-import'
@@ -1951,44 +1945,80 @@ async function bundleConfigFile(
}
throw e
}
if (!idFsPath) return
// always no-externalize json files as rolldown does not support import attributes
if (idFsPath.endsWith('.json')) {
return idFsPath
}

if (idFsPath && isImport) {
idFsPath = pathToFileURL(idFsPath).href
}
return {
path: idFsPath,
external: true,
}
return { id: idFsPath, external: true }
},
)
},
},
},
}
})(),
{
name: 'inject-file-scope-variables',
setup(build) {
build.onLoad({ filter: /\.[cm]?[jt]s$/ }, async (args) => {
const contents = await fsp.readFile(args.path, 'utf-8')
transform: {
filter: { id: /\.[cm]?[jt]s$/ },
async handler(code, id) {
const injectValues =
`const ${dirnameVarName} = ${JSON.stringify(
path.dirname(args.path),
)};` +
`const ${filenameVarName} = ${JSON.stringify(args.path)};` +
`const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};` +
`const ${filenameVarName} = ${JSON.stringify(id)};` +
`const ${importMetaUrlVarName} = ${JSON.stringify(
pathToFileURL(args.path).href,
pathToFileURL(id).href,
)};`

return {
loader: args.path.endsWith('ts') ? 'ts' : 'js',
contents: injectValues + contents,
}
})
return { code: injectValues + code, map: null }
},
},
},
],
})
const { text } = result.outputFiles[0]
const result = await bundle.generate({
format: isESM ? 'esm' : 'cjs',
sourcemap: 'inline',
})
await bundle.close()

const entryChunk = result.output.find(
(chunk): chunk is OutputChunk => chunk.type === 'chunk' && chunk.isEntry,
)!
const bundleChunks = Object.fromEntries(
result.output.flatMap((c) => (c.type === 'chunk' ? [[c.fileName, c]] : [])),
)

const allModules = new Set<string>()
collectAllModules(bundleChunks, entryChunk.fileName, allModules)
allModules.delete(fileName)

return {
code: text,
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : [],
code: entryChunk.code,
dependencies: [...allModules],
}
}

function collectAllModules(
bundle: Record<string, OutputChunk>,
fileName: string,
allModules: Set<string>,
analyzedModules = new Set<string>(),
) {
if (analyzedModules.has(fileName)) return
analyzedModules.add(fileName)

const chunk = bundle[fileName]!
for (const mod of chunk.moduleIds) {
allModules.add(mod)
}
for (const i of chunk.imports) {
analyzedModules.add(i)
collectAllModules(bundle, i, allModules, analyzedModules)
}
for (const i of chunk.dynamicImports) {
analyzedModules.add(i)
collectAllModules(bundle, i, allModules, analyzedModules)
}
}