Skip to content

Commit

Permalink
migrate native plugin (vitejs#41)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

* update justfile

* alias plugin

* update plugin config

* update plugin config

* update plugin config

* update config

* update config

* update config

* chore: 🤖 enable more plugin
  • Loading branch information
IWANABETHATGUY authored Sep 11, 2024
1 parent 5f1136e commit fe71cbc
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 18 deletions.
11 changes: 11 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
build-vite:
pnpm --filter vite run build-bundle

test-serve:
pnpm run test-serve

test-build:
pnpm run test-build

test: test-serve test-build

fmt:
pnpm --filter vite run format
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ export async function resolveConfig(
experimental: {
importGlobRestoreExtension: false,
hmrPartialAccept: false,
enableNativePlugin: true,
enableNativePlugin: false,
...config.experimental,
},
getSortedPlugins: undefined!,
Expand Down
75 changes: 58 additions & 17 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import aliasPlugin, { type ResolverFunction } from '@rollup/plugin-alias'
import type { ObjectHook } from 'rolldown'
import {
aliasPlugin as nativeAliasPlugin,
dynamicImportVarsPlugin as nativeDynamicImportVarsPlugin,
importGlobPlugin as nativeImportGlobPlugin,
jsonPlugin as nativeJsonPlugin,
modulePreloadPolyfillPlugin as nativeModulePreloadPolyfillPlugin,
transformPlugin as nativeTransformPlugin,
wasmFallbackPlugin as nativeWasmFallbackPlugin,
wasmHelperPlugin as nativeWasmHelperPlugin,
} from 'rolldown/experimental'
import type { PluginHookUtils, ResolvedConfig } from '../config'
import { isDepsOptimizerEnabled } from '../config'
import type { HookHandler, Plugin, PluginWithRequiredHook } from '../plugin'
Expand Down Expand Up @@ -39,6 +49,7 @@ export async function resolvePlugins(
? await (await import('../build')).resolveBuildPlugins(config)
: { pre: [], post: [] }
const { modulePreload } = config.build
const enableNativePlugin = config.experimental.enableNativePlugin
const depsOptimizerEnabled =
!isBuild &&
(isDepsOptimizerEnabled(config, false) ||
Expand All @@ -48,13 +59,26 @@ export async function resolvePlugins(
isBuild ? metadataPlugin() : null,
!isWorker ? watchPackageDataPlugin(config.packageCache) : null,
preAliasPlugin(config),
aliasPlugin({
entries: config.resolve.alias,
customResolver: viteAliasCustomResolver,
}),
enableNativePlugin
? nativeAliasPlugin({
entries: config.resolve.alias.map((item) => {
return {
find: item.find,
replacement: item.replacement,
}
}),
})
: aliasPlugin({
entries: config.resolve.alias,
customResolver: viteAliasCustomResolver,
}),
...prePlugins,
modulePreload !== false && modulePreload.polyfill
? modulePreloadPolyfillPlugin(config)
? enableNativePlugin
? nativeModulePreloadPolyfillPlugin({
skip: Boolean(config.command !== 'build' || config.build.ssr),
})
: modulePreloadPolyfillPlugin(config)
: null,
resolvePlugin({
...config.resolve,
Expand All @@ -75,27 +99,44 @@ export async function resolvePlugins(
}),
htmlInlineProxyPlugin(config),
cssPlugin(config),
config.esbuild !== false ? esbuildPlugin(config) : null,
jsonPlugin(
{
namedExports: true,
...config.json,
},
isBuild,
),
wasmHelperPlugin(config),
config.esbuild !== false
? enableNativePlugin
? nativeTransformPlugin()
: esbuildPlugin(config)
: null,
enableNativePlugin
? nativeJsonPlugin({
stringify: config.json?.stringify,
isBuild,
})
: jsonPlugin(
{
namedExports: true,
...config.json,
},
isBuild,
),
enableNativePlugin ? nativeWasmHelperPlugin() : wasmHelperPlugin(config),
webWorkerPlugin(config),
assetPlugin(config),
...normalPlugins,
wasmFallbackPlugin(),
enableNativePlugin ? nativeWasmFallbackPlugin() : wasmFallbackPlugin(),
// TODO: support nativedefinePlugin
definePlugin(config),
cssPostPlugin(config),
isBuild && buildHtmlPlugin(config),
workerImportMetaUrlPlugin(config),
assetImportMetaUrlPlugin(config),
...buildPlugins.pre,
dynamicImportVarsPlugin(config),
importGlobPlugin(config),
enableNativePlugin
? nativeDynamicImportVarsPlugin()
: dynamicImportVarsPlugin(config),
enableNativePlugin
? nativeImportGlobPlugin({
root: config.root,
restoreQueryExtension: config.experimental.importGlobRestoreExtension,
})
: importGlobPlugin(config),
...postPlugins,
...buildPlugins.post,
// internal server-only plugins are always applied after everything else
Expand Down

0 comments on commit fe71cbc

Please sign in to comment.