Skip to content

Commit d6b9c56

Browse files
committed
feat: init
1 parent 69c482b commit d6b9c56

File tree

19 files changed

+531
-228
lines changed

19 files changed

+531
-228
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"picocolors": "^1.1.1",
6565
"playwright-chromium": "^1.57.0",
6666
"prettier": "3.6.2",
67-
"rolldown": "1.0.0-beta.52",
67+
"rolldown": "https://pkg.pr.new/rolldown@819952d",
6868
"rollup": "^4.43.0",
6969
"simple-git-hooks": "^2.13.1",
7070
"tsx": "^4.20.6",

packages/vite/package.json

Lines changed: 1 addition & 1 deletion
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.52",
90+
"rolldown": "https://pkg.pr.new/rolldown@819952d",
9191
"tinyglobby": "^0.2.15"
9292
},
9393
"optionalDependencies": {

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/config.ts

Lines changed: 105 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -603,109 +603,108 @@ export interface InlineConfig extends UserConfig {
603603
forceOptimizeDeps?: boolean
604604
}
605605

606-
export interface ResolvedConfig
607-
extends Readonly<
608-
Omit<
609-
UserConfig,
610-
| 'plugins'
611-
| 'css'
612-
| 'json'
613-
| 'assetsInclude'
614-
| 'optimizeDeps'
615-
| 'worker'
616-
| 'build'
617-
| 'dev'
618-
| 'environments'
619-
| 'experimental'
620-
| 'future'
621-
| 'server'
622-
| 'preview'
623-
> & {
624-
configFile: string | undefined
625-
configFileDependencies: string[]
626-
inlineConfig: InlineConfig
627-
root: string
628-
base: string
629-
/** @internal */
630-
decodedBase: string
631-
/** @internal */
632-
rawBase: string
633-
publicDir: string
634-
cacheDir: string
635-
command: 'build' | 'serve'
636-
mode: string
637-
isWorker: boolean
638-
// in nested worker bundle to find the main config
639-
/** @internal */
640-
mainConfig: ResolvedConfig | null
641-
/** @internal list of bundle entry id. used to detect recursive worker bundle. */
642-
bundleChain: string[]
643-
isProduction: boolean
644-
envDir: string | false
645-
env: Record<string, any>
646-
resolve: Required<ResolveOptions> & {
647-
alias: Alias[]
648-
}
649-
plugins: readonly Plugin[]
650-
css: ResolvedCSSOptions
651-
json: Required<JsonOptions>
652-
/** @deprecated Use `oxc` option instead. */
653-
esbuild: ESBuildOptions | false
654-
oxc: OxcOptions | false
655-
server: ResolvedServerOptions
656-
dev: ResolvedDevEnvironmentOptions
657-
/** @experimental */
658-
builder: ResolvedBuilderOptions | undefined
659-
build: ResolvedBuildOptions
660-
preview: ResolvedPreviewOptions
661-
ssr: ResolvedSSROptions
662-
assetsInclude: (file: string) => boolean
663-
rawAssetsInclude: (string | RegExp)[]
664-
logger: Logger
665-
/**
666-
* Create an internal resolver to be used in special scenarios, e.g.
667-
* optimizer & handling css `@imports`.
668-
*
669-
* This API is deprecated. It only works for the client and ssr
670-
* environments. The `aliasOnly` option is also not being used anymore.
671-
* Plugins should move to `createIdResolver(environment.config)` instead.
672-
*
673-
* @deprecated Use `createIdResolver` from `vite` instead.
674-
*/
675-
createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn
676-
optimizeDeps: DepOptimizationOptions
677-
/** @internal */
678-
packageCache: PackageCache
679-
worker: ResolvedWorkerOptions
680-
appType: AppType
681-
experimental: RequiredExceptFor<ExperimentalOptions, 'renderBuiltUrl'>
682-
future: FutureOptions | undefined
683-
environments: Record<string, ResolvedEnvironmentOptions>
684-
/** @internal injected by legacy plugin */
685-
isOutputOptionsForLegacyChunks?(
686-
outputOptions: NormalizedOutputOptions,
687-
): boolean
688-
/**
689-
* The token to connect to the WebSocket server from browsers.
690-
*
691-
* We recommend using `import.meta.hot` rather than connecting
692-
* to the WebSocket server directly.
693-
* If you have a usecase that requires connecting to the WebSocket
694-
* server, please create an issue so that we can discuss.
695-
*
696-
* @deprecated
697-
*/
698-
webSocketToken: string
699-
/** @internal */
700-
fsDenyGlob: AnymatchFn
701-
/** @internal */
702-
safeModulePaths: Set<string>
703-
/** @internal */
704-
nativePluginEnabledLevel: number
705-
/** @internal */
706-
[SYMBOL_RESOLVED_CONFIG]: true
707-
} & PluginHookUtils
708-
> {}
606+
export interface ResolvedConfig extends Readonly<
607+
Omit<
608+
UserConfig,
609+
| 'plugins'
610+
| 'css'
611+
| 'json'
612+
| 'assetsInclude'
613+
| 'optimizeDeps'
614+
| 'worker'
615+
| 'build'
616+
| 'dev'
617+
| 'environments'
618+
| 'experimental'
619+
| 'future'
620+
| 'server'
621+
| 'preview'
622+
> & {
623+
configFile: string | undefined
624+
configFileDependencies: string[]
625+
inlineConfig: InlineConfig
626+
root: string
627+
base: string
628+
/** @internal */
629+
decodedBase: string
630+
/** @internal */
631+
rawBase: string
632+
publicDir: string
633+
cacheDir: string
634+
command: 'build' | 'serve'
635+
mode: string
636+
isWorker: boolean
637+
// in nested worker bundle to find the main config
638+
/** @internal */
639+
mainConfig: ResolvedConfig | null
640+
/** @internal list of bundle entry id. used to detect recursive worker bundle. */
641+
bundleChain: string[]
642+
isProduction: boolean
643+
envDir: string | false
644+
env: Record<string, any>
645+
resolve: Required<ResolveOptions> & {
646+
alias: Alias[]
647+
}
648+
plugins: readonly Plugin[]
649+
css: ResolvedCSSOptions
650+
json: Required<JsonOptions>
651+
/** @deprecated Use `oxc` option instead. */
652+
esbuild: ESBuildOptions | false
653+
oxc: OxcOptions | false
654+
server: ResolvedServerOptions
655+
dev: ResolvedDevEnvironmentOptions
656+
/** @experimental */
657+
builder: ResolvedBuilderOptions | undefined
658+
build: ResolvedBuildOptions
659+
preview: ResolvedPreviewOptions
660+
ssr: ResolvedSSROptions
661+
assetsInclude: (file: string) => boolean
662+
rawAssetsInclude: (string | RegExp)[]
663+
logger: Logger
664+
/**
665+
* Create an internal resolver to be used in special scenarios, e.g.
666+
* optimizer & handling css `@imports`.
667+
*
668+
* This API is deprecated. It only works for the client and ssr
669+
* environments. The `aliasOnly` option is also not being used anymore.
670+
* Plugins should move to `createIdResolver(environment.config)` instead.
671+
*
672+
* @deprecated Use `createIdResolver` from `vite` instead.
673+
*/
674+
createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn
675+
optimizeDeps: DepOptimizationOptions
676+
/** @internal */
677+
packageCache: PackageCache
678+
worker: ResolvedWorkerOptions
679+
appType: AppType
680+
experimental: RequiredExceptFor<ExperimentalOptions, 'renderBuiltUrl'>
681+
future: FutureOptions | undefined
682+
environments: Record<string, ResolvedEnvironmentOptions>
683+
/** @internal injected by legacy plugin */
684+
isOutputOptionsForLegacyChunks?(
685+
outputOptions: NormalizedOutputOptions,
686+
): boolean
687+
/**
688+
* The token to connect to the WebSocket server from browsers.
689+
*
690+
* We recommend using `import.meta.hot` rather than connecting
691+
* to the WebSocket server directly.
692+
* If you have a usecase that requires connecting to the WebSocket
693+
* server, please create an issue so that we can discuss.
694+
*
695+
* @deprecated
696+
*/
697+
webSocketToken: string
698+
/** @internal */
699+
fsDenyGlob: AnymatchFn
700+
/** @internal */
701+
safeModulePaths: Set<string>
702+
/** @internal */
703+
nativePluginEnabledLevel: number
704+
/** @internal */
705+
[SYMBOL_RESOLVED_CONFIG]: true
706+
} & PluginHookUtils
707+
> {}
709708

710709
// inferred ones are omitted
711710
const configDefaults = Object.freeze({
@@ -769,7 +768,7 @@ const configDefaults = Object.freeze({
769768
importGlobRestoreExtension: false,
770769
renderBuiltUrl: undefined,
771770
hmrPartialAccept: false,
772-
enableNativePlugin: process.env._VITE_TEST_JS_PLUGIN ? false : 'v1',
771+
enableNativePlugin: process.env._VITE_TEST_JS_PLUGIN ? false : true,
773772
},
774773
future: {
775774
removePluginHookHandleHotUpdate: undefined,
@@ -2061,8 +2060,9 @@ function resolveNativePluginEnabledLevel(
20612060
case 'resolver':
20622061
return 0
20632062
case 'v1':
2064-
case true:
20652063
return 1
2064+
case true:
2065+
return 2
20662066
case false:
20672067
return -1
20682068
default:

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 >= 2) {
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/assetImportMetaUrl.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import path from 'node:path'
22
import MagicString from 'magic-string'
33
import { stripLiteral } from 'strip-literal'
44
import { exactRegex } from '@rolldown/pluginutils'
5-
import type { Plugin } from '../plugin'
5+
import { viteAssetImportMetaUrlPlugin } from 'rolldown/experimental'
6+
import { type Plugin, perEnvironmentPlugin } from '../plugin'
67
import type { ResolvedConfig } from '../config'
78
import {
89
injectQuery,
@@ -44,6 +45,30 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
4445
asSrc: true,
4546
}
4647

48+
if (config.command === 'build' && config.nativePluginEnabledLevel >= 2) {
49+
return perEnvironmentPlugin('vite:native-asset-import-meta-url', (env) => {
50+
if (env.config.consumer === 'client') {
51+
return viteAssetImportMetaUrlPlugin({
52+
root: env.config.root,
53+
isLib: !!env.config.build.lib,
54+
publicDir: env.config.publicDir,
55+
clientEntry: CLIENT_ENTRY,
56+
assetInlineLimit: env.config.build.assetsInlineLimit,
57+
tryFsResolve: (file) => tryFsResolve(file, fsResolveOptions),
58+
assetResolver: (url, importer) => {
59+
assetResolver ??= createBackCompatIdResolver(env.config, {
60+
extensions: [],
61+
mainFields: [],
62+
tryIndex: false,
63+
preferRelative: true,
64+
})
65+
return assetResolver(env, url, importer)
66+
},
67+
})
68+
}
69+
})
70+
}
71+
4772
return {
4873
name: 'vite:asset-import-meta-url',
4974

0 commit comments

Comments
 (0)