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 { isDepOptimizationDisabled } from '../optimizer'
5
15
import type { HookHandler , Plugin , PluginWithRequiredHook } from '../plugin'
@@ -42,21 +52,35 @@ export async function resolvePlugins(
42
52
Object . values ( config . environments ) . some (
43
53
( environment ) => ! isDepOptimizationDisabled ( environment . dev . optimizeDeps ) ,
44
54
)
55
+ const enableNativePlugin = config . experimental . enableNativePlugin
45
56
46
57
return [
47
58
depOptimizationEnabled ? optimizedDepsPlugin ( ) : null ,
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
56
76
...prePlugins ,
57
77
58
78
modulePreload !== false && modulePreload . polyfill
59
- ? modulePreloadPolyfillPlugin ( config )
79
+ ? enableNativePlugin
80
+ ? nativeModulePreloadPolyfillPlugin ( {
81
+ skip : Boolean ( config . command !== 'build' || config . build . ssr ) ,
82
+ } )
83
+ : modulePreloadPolyfillPlugin ( config )
60
84
: null ,
61
85
resolvePlugin (
62
86
{
@@ -73,29 +97,46 @@ export async function resolvePlugins(
73
97
) ,
74
98
htmlInlineProxyPlugin ( config ) ,
75
99
cssPlugin ( config ) ,
76
- config . esbuild !== false ? esbuildPlugin ( config ) : null ,
77
- jsonPlugin (
78
- {
79
- namedExports : true ,
80
- ...config . json ,
81
- } ,
82
- isBuild ,
83
- ) ,
84
- wasmHelperPlugin ( ) ,
100
+ config . esbuild !== false
101
+ ? enableNativePlugin
102
+ ? nativeTransformPlugin ( )
103
+ : esbuildPlugin ( config )
104
+ : null ,
105
+ enableNativePlugin
106
+ ? nativeJsonPlugin ( {
107
+ stringify : config . json ?. stringify ,
108
+ isBuild,
109
+ } )
110
+ : jsonPlugin (
111
+ {
112
+ namedExports : true ,
113
+ ...config . json ,
114
+ } ,
115
+ isBuild ,
116
+ ) ,
117
+ enableNativePlugin ? nativeWasmHelperPlugin ( ) : wasmHelperPlugin ( ) ,
85
118
webWorkerPlugin ( config ) ,
86
119
assetPlugin ( config ) ,
87
120
88
121
...normalPlugins ,
89
122
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
100
141
...postPlugins ,
101
142
0 commit comments