Skip to content

Commit 097a16d

Browse files
committed
feat: init
1 parent edab97e commit 097a16d

File tree

21 files changed

+575
-312
lines changed

21 files changed

+575
-312
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"picocolors": "^1.1.1",
6666
"playwright-chromium": "^1.56.1",
6767
"prettier": "3.6.2",
68-
"rolldown": "1.0.0-beta.50",
68+
"rolldown": "https://pkg.pr.new/rolldown@7087",
6969
"rollup": "^4.43.0",
7070
"simple-git-hooks": "^2.13.1",
7171
"tsx": "^4.20.6",

packages/vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"lightningcss": "^1.30.2",
8888
"picomatch": "^4.0.3",
8989
"postcss": "^8.5.6",
90-
"rolldown": "1.0.0-beta.50",
90+
"rolldown": "https://pkg.pr.new/rolldown@7087",
9191
"tinyglobby": "^0.2.15"
9292
},
9393
"optionalDependencies": {
@@ -99,7 +99,7 @@
9999
"@jridgewell/trace-mapping": "^0.3.31",
100100
"@oxc-project/types": "0.97.0",
101101
"@polka/compression": "^1.0.0-next.25",
102-
"@rolldown/pluginutils": "^1.0.0-beta.46",
102+
"@rolldown/pluginutils": "https://pkg.pr.new/@rolldown/pluginutils@e8641b3",
103103
"@rollup/plugin-alias": "^5.1.1",
104104
"@rollup/plugin-commonjs": "28.0.6",
105105
"@rollup/plugin-dynamic-import-vars": "2.1.4",

packages/vite/src/node/__tests__/plugins/hooks.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe('supports plugin context', () => {
210210
})
211211

212212
test('transformIndexHtml hook in build', async () => {
213-
expect.assertions(4)
213+
expect.assertions(3)
214214

215215
await buildWithPlugin({
216216
name: 'test',
@@ -223,7 +223,7 @@ describe('supports plugin context', () => {
223223
meta: expect.any(Object),
224224
})
225225
expect(this.meta.rollupVersion).toBeTypeOf('string')
226-
expect(this.meta.viteVersion).toBeTypeOf('string')
226+
// expect(this.meta.viteVersion).toBeTypeOf('string')
227227
expect(this.meta.watchMode).toBe(false)
228228
},
229229
})

packages/vite/src/node/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
WarningHandlerWithDefault,
2323
WatcherOptions,
2424
} from 'rolldown'
25-
import { loadFallbackPlugin as nativeLoadFallbackPlugin } from 'rolldown/experimental'
25+
import { viteLoadFallbackPlugin as nativeLoadFallbackPlugin } from 'rolldown/experimental'
2626
import type { EsbuildTarget } from '#types/internal/esbuildOptions'
2727
import type { RollupCommonJSOptions } from '#dep-types/commonjs'
2828
import type { RollupDynamicImportVarsOptions } from '#dep-types/dynamicImportVars'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { reactRefreshWrapperPlugin } from 'rolldown/experimental'
1+
export { viteReactRefreshWrapperPlugin as reactRefreshWrapperPlugin } from 'rolldown/experimental'

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'node:path'
22
import fsp from 'node:fs/promises'
33
import { Buffer } from 'node:buffer'
44
import * as mrmime from 'mrmime'
5+
import { viteAssetPlugin as nativeAssetPlugin } from 'rolldown/experimental'
56
import type {
67
NormalizedOutputOptions,
78
PluginContext,
@@ -15,7 +16,7 @@ import {
1516
createToImportMetaURLBasedRelativeRuntime,
1617
toOutputFilePathInJS,
1718
} from '../build'
18-
import type { Plugin } from '../plugin'
19+
import { type Plugin, perEnvironmentPlugin } from '../plugin'
1920
import type { ResolvedConfig } from '../config'
2021
import { checkPublicFile } from '../publicDir'
2122
import {
@@ -148,6 +149,23 @@ export function renderAssetUrlInJS(
148149
* Also supports loading plain strings with import text from './foo.txt?raw'
149150
*/
150151
export function assetPlugin(config: ResolvedConfig): Plugin {
152+
if (config.command === 'build' && config.nativePluginEnabledLevel >= 1) {
153+
return perEnvironmentPlugin('native:asset', (env) => {
154+
return nativeAssetPlugin({
155+
root: env.config.root,
156+
isLib: !!env.config.build.lib,
157+
isSsr: !!env.config.build.ssr,
158+
isWorker: env.config.isWorker,
159+
urlBase: env.config.base,
160+
publicDir: env.config.publicDir,
161+
decodedBase: env.config.decodedBase,
162+
isSkipAssets: !env.config.build.emitAssets,
163+
assetInlineLimit: env.config.build.assetsInlineLimit,
164+
assetsInclude: env.config.rawAssetsInclude,
165+
})
166+
})
167+
}
168+
151169
registerCustomMime()
152170

153171
return {

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

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type {
2727
TransformAttributeResult as LightningCssTransformAttributeResult,
2828
TransformResult as LightningCssTransformResult,
2929
} from 'lightningcss'
30+
import { viteCSSPlugin, viteCSSPostPlugin } from 'rolldown/experimental'
3031
import type { LightningCSSOptions } from '#types/internal/lightningcssOptions'
3132
import type {
3233
LessPreprocessorBaseOptions,
@@ -89,7 +90,7 @@ import type { ResolveIdFn } from '../idResolver'
8990
import { PartialEnvironment } from '../baseEnvironment'
9091
import type { TransformPluginContext } from '../server/pluginContainer'
9192
import { searchForWorkspaceRoot } from '../server/searchRoot'
92-
import { type DevEnvironment } from '..'
93+
import { type DevEnvironment, perEnvironmentPlugin } from '..'
9394
import type { PackageCache } from '../packages'
9495
import { findNearestMainPackageData } from '../packages'
9596
import { nodeResolveWithVite } from '../nodeResolve'
@@ -311,6 +312,49 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
311312
})
312313
}
313314

315+
if (isBuild && config.nativePluginEnabledLevel >= 1) {
316+
return perEnvironmentPlugin('vite:native-css', (env) => {
317+
return [
318+
{
319+
name: 'vite:css-compat',
320+
buildStart() {
321+
preprocessorWorkerController = createPreprocessorWorkerController(
322+
normalizeMaxWorkers(config.css.preprocessorMaxWorkers),
323+
)
324+
preprocessorWorkerControllerCache.set(
325+
config,
326+
preprocessorWorkerController,
327+
)
328+
},
329+
330+
buildEnd() {
331+
preprocessorWorkerController?.close()
332+
},
333+
},
334+
viteCSSPlugin({
335+
root: env.config.root,
336+
isLib: !!env.config.build.lib,
337+
publicDir: env.config.publicDir,
338+
async compileCSS(url, importer, resolver) {
339+
return compileCSS(
340+
env,
341+
url,
342+
importer,
343+
preprocessorWorkerController!,
344+
(url, importer) => {
345+
return resolver.call(url, importer)
346+
},
347+
)
348+
},
349+
resolveUrl(url, importer) {
350+
return idResolver(env, url, importer)
351+
},
352+
assetInlineLimit: env.config.build.assetsInlineLimit,
353+
}),
354+
]
355+
})
356+
}
357+
314358
return {
315359
name: 'vite:css',
316360

@@ -506,6 +550,46 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
506550
return cssBundleName
507551
}
508552

553+
if (config.command === 'build' && config.nativePluginEnabledLevel >= 1) {
554+
const isLegacySet = new Set<string>()
555+
return perEnvironmentPlugin('native:css-post', (env) => {
556+
return [
557+
{
558+
name: 'native:css-post-compat',
559+
...(config.isOutputOptionsForLegacyChunks
560+
? {
561+
renderChunk(_, __, opts) {
562+
const isLegacy =
563+
env.config.isOutputOptionsForLegacyChunks?.(opts) ?? false
564+
if (isLegacy) {
565+
isLegacySet.add(env.name)
566+
} else {
567+
isLegacySet.delete(env.name)
568+
}
569+
},
570+
}
571+
: {}),
572+
},
573+
viteCSSPostPlugin({
574+
root: env.config.root,
575+
isLib: !!env.config.build.lib,
576+
isSsr: !!env.config.build.ssr,
577+
isWorker: env.config.isWorker,
578+
isLegacy: env.config.isOutputOptionsForLegacyChunks
579+
? () => isLegacySet.has(env.name)
580+
: undefined,
581+
isClient: env.config.consumer === 'client',
582+
cssCodeSplit: env.config.build.cssCodeSplit,
583+
sourcemap: !!env.config.build.sourcemap,
584+
assetsDir: env.config.build.assetsDir,
585+
urlBase: env.config.base,
586+
decodedBase: env.config.decodedBase,
587+
renderBuiltUrl: env.config.experimental.renderBuiltUrl,
588+
}),
589+
]
590+
})
591+
}
592+
509593
return {
510594
name: 'vite:css-post',
511595

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { init, parse as parseImports } from 'es-module-lexer'
44
import type { ImportSpecifier } from 'es-module-lexer'
55
import { parseAst } from 'rolldown/parseAst'
66
import { dynamicImportToGlob } from '@rollup/plugin-dynamic-import-vars'
7-
import { dynamicImportVarsPlugin as nativeDynamicImportVarsPlugin } from 'rolldown/experimental'
7+
import { viteDynamicImportVarsPlugin as nativeDynamicImportVarsPlugin } from 'rolldown/experimental'
88
import { exactRegex } from '@rolldown/pluginutils'
99
import { type Plugin, perEnvironmentPlugin } from '../plugin'
1010
import type { ResolvedConfig } from '../config'

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ import type {
1717
} from 'parse5'
1818
import { stripLiteral } from 'strip-literal'
1919
import escapeHtml from 'escape-html'
20-
import type { MinimalPluginContextWithoutEnvironment, Plugin } from '../plugin'
20+
import {
21+
viteHtmlInlineProxyPlugin as nativeHtmlInlineProxyPlugin,
22+
viteHtmlPlugin,
23+
} from 'rolldown/experimental'
24+
import {
25+
type MinimalPluginContextWithoutEnvironment,
26+
type Plugin,
27+
perEnvironmentPlugin,
28+
} from '../plugin'
2129
import type { ViteDevServer } from '../server'
2230
import {
2331
decodeURIIfPossible,
@@ -101,6 +109,12 @@ export const htmlProxyMap: WeakMap<
101109
export const htmlProxyResult: Map<string, string> = new Map()
102110

103111
export function htmlInlineProxyPlugin(config: ResolvedConfig): Plugin {
112+
if (config.command === 'build' && config.nativePluginEnabledLevel >= 1) {
113+
return nativeHtmlInlineProxyPlugin({
114+
root: config.root,
115+
})
116+
}
117+
104118
// Should do this when `constructor` rather than when `buildStart`,
105119
// `buildStart` will be triggered multiple times then the cached result will be emptied.
106120
// https://github.com/vitejs/vite/issues/6372
@@ -366,6 +380,33 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
366380
// Same reason with `htmlInlineProxyPlugin`
367381
isAsyncScriptMap.set(config, new Map())
368382

383+
if (config.command === 'build' && config.nativePluginEnabledLevel >= 1) {
384+
return perEnvironmentPlugin('native:vite-html', (env) => {
385+
return viteHtmlPlugin({
386+
root: env.config.root,
387+
isLib: !!env.config.build.lib,
388+
isSsr: !!env.config.build.ssr,
389+
urlBase: env.config.base,
390+
publicDir: env.config.publicDir,
391+
decodedBase: env.config.decodedBase,
392+
modulePreload: env.config.build.modulePreload,
393+
cssCodeSplit: env.config.build.cssCodeSplit,
394+
assetInlineLimit: env.config.build.assetsInlineLimit,
395+
preHooks,
396+
normalHooks,
397+
postHooks,
398+
async applyHtmlTransforms(html, hooks, pluginContext, ctx) {
399+
return applyHtmlTransforms(
400+
html,
401+
hooks as IndexHtmlTransformHook[],
402+
pluginContext,
403+
ctx,
404+
)
405+
},
406+
})
407+
})
408+
}
409+
369410
return {
370411
name: 'vite:build-html',
371412

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
} from 'es-module-lexer'
77
import { init, parse as parseImports } from 'es-module-lexer'
88
import type { SourceMap } from 'rolldown'
9-
import { buildImportAnalysisPlugin as nativeBuildImportAnalysisPlugin } from 'rolldown/experimental'
9+
import { viteBuildImportAnalysisPlugin as nativeBuildImportAnalysisPlugin } from 'rolldown/experimental'
1010
import type { RawSourceMap } from '@jridgewell/remapping'
1111
import convertSourceMap from 'convert-source-map'
1212
import { exactRegex } from '@rolldown/pluginutils'
@@ -745,24 +745,27 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin[] {
745745
}
746746

747747
if (config.nativePluginEnabledLevel >= 1) {
748-
delete plugin.transform
749-
delete plugin.resolveId
750-
delete plugin.load
751748
return [
752-
plugin,
753-
perEnvironmentPlugin('native:import-analysis-build', (environment) => {
749+
perEnvironmentPlugin('native:import-analysis-build', (env) => {
754750
const preloadCode = getPreloadCode(
755-
environment,
751+
env,
756752
!!renderBuiltUrl,
757753
isRelativeBase,
758754
)
759755
return nativeBuildImportAnalysisPlugin({
760756
preloadCode,
761-
insertPreload: getInsertPreload(environment),
757+
insertPreload: getInsertPreload(env),
762758
// this field looks redundant, put a dummy value for now
763759
optimizeModulePreloadRelativePaths: false,
764760
renderBuiltUrl: !!renderBuiltUrl,
765761
isRelativeBase,
762+
v2: {
763+
isSsr: !!env.config.build.ssr,
764+
urlBase: env.config.base,
765+
decodedBase: env.config.decodedBase,
766+
modulePreload: env.config.build.modulePreload,
767+
renderBuiltUrl: env.config.experimental.renderBuiltUrl,
768+
},
766769
})
767770
}),
768771
]

0 commit comments

Comments
 (0)