1
1
import aliasPlugin , { type ResolverFunction } from '@rollup/plugin-alias'
2
2
import type { ObjectHook } from 'rolldown'
3
+ import {
4
+ aliasPlugin as nativeAliasPlugin ,
5
+ dynamicImportVarsPlugin as nativeDynamicImportVarsPlugin ,
6
+ importGlobPlugin as nativeImportGlobPlugin ,
7
+ jsonPlugin as nativeJsonPlugin ,
8
+ modulePreloadPolyfillPlugin as nativeModulePreloadPolyfillPlugin ,
9
+ transformPlugin as nativeTransformPlugin ,
10
+ wasmFallbackPlugin as nativeWasmFallbackPlugin ,
11
+ wasmHelperPlugin as nativeWasmHelperPlugin ,
12
+ } from 'rolldown/experimental'
3
13
import type { PluginHookUtils , ResolvedConfig } from '../config'
4
14
import { isDepsOptimizerEnabled } from '../config'
5
15
import type { HookHandler , Plugin , PluginWithRequiredHook } from '../plugin'
@@ -39,6 +49,7 @@ export async function resolvePlugins(
39
49
? await ( await import ( '../build' ) ) . resolveBuildPlugins ( config )
40
50
: { pre : [ ] , post : [ ] }
41
51
const { modulePreload } = config . build
52
+ const enableNativePlugin = config . experimental . enableNativePlugin
42
53
const depsOptimizerEnabled =
43
54
! isBuild &&
44
55
( isDepsOptimizerEnabled ( config , false ) ||
@@ -48,13 +59,26 @@ export async function resolvePlugins(
48
59
isBuild ? metadataPlugin ( ) : null ,
49
60
! isWorker ? watchPackageDataPlugin ( config . packageCache ) : null ,
50
61
preAliasPlugin ( config ) ,
51
- aliasPlugin ( {
52
- entries : config . resolve . alias ,
53
- customResolver : viteAliasCustomResolver ,
54
- } ) ,
62
+ enableNativePlugin
63
+ ? nativeAliasPlugin ( {
64
+ entries : config . resolve . alias . map ( ( item ) => {
65
+ return {
66
+ find : item . find ,
67
+ replacement : item . replacement ,
68
+ }
69
+ } ) ,
70
+ } )
71
+ : aliasPlugin ( {
72
+ entries : config . resolve . alias ,
73
+ customResolver : viteAliasCustomResolver ,
74
+ } ) ,
55
75
...prePlugins ,
56
76
modulePreload !== false && modulePreload . polyfill
57
- ? modulePreloadPolyfillPlugin ( config )
77
+ ? enableNativePlugin
78
+ ? nativeModulePreloadPolyfillPlugin ( {
79
+ skip : Boolean ( config . command !== 'build' || config . build . ssr ) ,
80
+ } )
81
+ : modulePreloadPolyfillPlugin ( config )
58
82
: null ,
59
83
resolvePlugin ( {
60
84
...config . resolve ,
@@ -75,27 +99,44 @@ export async function resolvePlugins(
75
99
} ) ,
76
100
htmlInlineProxyPlugin ( config ) ,
77
101
cssPlugin ( config ) ,
78
- config . esbuild !== false ? esbuildPlugin ( config ) : null ,
79
- jsonPlugin (
80
- {
81
- namedExports : true ,
82
- ...config . json ,
83
- } ,
84
- isBuild ,
85
- ) ,
86
- wasmHelperPlugin ( config ) ,
102
+ config . esbuild !== false
103
+ ? enableNativePlugin
104
+ ? nativeTransformPlugin ( )
105
+ : esbuildPlugin ( config )
106
+ : null ,
107
+ enableNativePlugin
108
+ ? nativeJsonPlugin ( {
109
+ stringify : config . json ?. stringify ,
110
+ isBuild,
111
+ } )
112
+ : jsonPlugin (
113
+ {
114
+ namedExports : true ,
115
+ ...config . json ,
116
+ } ,
117
+ isBuild ,
118
+ ) ,
119
+ enableNativePlugin ? nativeWasmHelperPlugin ( ) : wasmHelperPlugin ( config ) ,
87
120
webWorkerPlugin ( config ) ,
88
121
assetPlugin ( config ) ,
89
122
...normalPlugins ,
90
- wasmFallbackPlugin ( ) ,
123
+ enableNativePlugin ? nativeWasmFallbackPlugin ( ) : wasmFallbackPlugin ( ) ,
124
+ // TODO: support nativedefinePlugin
91
125
definePlugin ( config ) ,
92
126
cssPostPlugin ( config ) ,
93
127
isBuild && buildHtmlPlugin ( config ) ,
94
128
workerImportMetaUrlPlugin ( config ) ,
95
129
assetImportMetaUrlPlugin ( config ) ,
96
130
...buildPlugins . pre ,
97
- dynamicImportVarsPlugin ( config ) ,
98
- importGlobPlugin ( config ) ,
131
+ enableNativePlugin
132
+ ? nativeDynamicImportVarsPlugin ( )
133
+ : dynamicImportVarsPlugin ( config ) ,
134
+ enableNativePlugin
135
+ ? nativeImportGlobPlugin ( {
136
+ root : config . root ,
137
+ restoreQueryExtension : config . experimental . importGlobRestoreExtension ,
138
+ } )
139
+ : importGlobPlugin ( config ) ,
99
140
...postPlugins ,
100
141
...buildPlugins . post ,
101
142
// internal server-only plugins are always applied after everything else
0 commit comments