diff --git a/docs/guide/api-environment-plugins.md b/docs/guide/api-environment-plugins.md index 151cf855d..da50a7033 100644 --- a/docs/guide/api-environment-plugins.md +++ b/docs/guide/api-environment-plugins.md @@ -128,7 +128,7 @@ The hook can choose to: ## Per-environment Plugins -A plugin can define what are the environments it should apply to with the `applyToEnvironment` function. +A plugin can define what are the environments it should apply to with the `perEnvironment` function. ```js const UnoCssPlugin = () => { @@ -141,7 +141,7 @@ const UnoCssPlugin = () => { configureServer() { // use global hooks normally }, - applyToEnvironment(environment) { + perEnvironment(environment) { // return true if this plugin should be active in this environment, // or return a new plugin to replace it. // if the hook is not used, the plugin is active in all environments @@ -153,7 +153,7 @@ const UnoCssPlugin = () => { } ``` -If a plugin isn't environment aware and has state that isn't keyed on the current environment, the `applyToEnvironment` hook allows to easily make it per-environment. +If a plugin isn't environment aware and has state that isn't keyed on the current environment, the `perEnvironment` hook allows to easily make it per-environment. ```js import { nonShareablePlugin } from 'non-shareable-plugin' @@ -162,7 +162,7 @@ export default defineConfig({ plugins: [ { name: 'per-environment-plugin', - applyToEnvironment(environment) { + perEnvironment(environment) { return nonShareablePlugin({ outputName: environment.name }) }, }, diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index 081324f2d..30cdfa9b8 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -207,7 +207,7 @@ export interface Plugin extends RollupPlugin { * By default, the plugin is active in all environments * @experimental */ - applyToEnvironment?: ( + perEnvironment?: ( environment: PartialEnvironment, ) => boolean | Promise | PluginOption /** @@ -334,8 +334,8 @@ export async function resolveEnvironmentPlugins( ): Promise { const environmentPlugins: Plugin[] = [] for (const plugin of environment.getTopLevelConfig().plugins) { - if (plugin.applyToEnvironment) { - const applied = await plugin.applyToEnvironment(environment) + if (plugin.perEnvironment) { + const applied = await plugin.perEnvironment(environment) if (!applied) { continue } @@ -358,12 +358,12 @@ export async function resolveEnvironmentPlugins( */ export function perEnvironmentPlugin( name: string, - applyToEnvironment: ( + perEnvironment: ( environment: PartialEnvironment, ) => boolean | Promise | PluginOption, ): Plugin { return { name, - applyToEnvironment, + perEnvironment, } } diff --git a/packages/vite/src/node/plugins/manifest.ts b/packages/vite/src/node/plugins/manifest.ts index 2832b8869..7a71ad9cd 100644 --- a/packages/vite/src/node/plugins/manifest.ts +++ b/packages/vite/src/node/plugins/manifest.ts @@ -42,7 +42,7 @@ export function manifestPlugin(): Plugin { perEnvironmentStartEndDuringDev: true, - applyToEnvironment(environment) { + perEnvironment(environment) { return !!environment.config.build.manifest }, diff --git a/packages/vite/src/node/plugins/terser.ts b/packages/vite/src/node/plugins/terser.ts index 9c254dee1..01571b9a5 100644 --- a/packages/vite/src/node/plugins/terser.ts +++ b/packages/vite/src/node/plugins/terser.ts @@ -59,7 +59,7 @@ export function terserPlugin(config: ResolvedConfig): Plugin { return { name: 'vite:terser', - applyToEnvironment(environment) { + perEnvironment(environment) { // We also need the plugin even if minify isn't 'terser' as we force // terser in plugin-legacy return !!environment.config.build.minify diff --git a/packages/vite/src/node/ssr/ssrManifestPlugin.ts b/packages/vite/src/node/ssr/ssrManifestPlugin.ts index 56f87400c..4c57b33a1 100644 --- a/packages/vite/src/node/ssr/ssrManifestPlugin.ts +++ b/packages/vite/src/node/ssr/ssrManifestPlugin.ts @@ -25,7 +25,7 @@ export function ssrManifestPlugin(): Plugin { return { name: 'vite:ssr-manifest', - applyToEnvironment(environment) { + perEnvironment(environment) { return !!environment.config.build.ssrManifest },