Skip to content

Commit

Permalink
fix: use environment.plugins during build, support create hook
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Apr 26, 2024
1 parent e6fa9d9 commit a44810a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
partialEncodeURIPath,
requireResolveFromRootWithFallback,
} from './utils'
import { resolveBoundedPlugins } from './plugin'
import { manifestPlugin } from './plugins/manifest'
import type { Logger } from './logger'
import { dataURIPlugin } from './plugins/dataUri'
Expand Down Expand Up @@ -605,11 +606,10 @@ export async function buildEnvironment(
const outDir = resolve(options.outDir)

// inject environment and ssr arg to plugin load/transform hooks
const plugins = (
environment || ssr
? config.plugins.map((p) => injectEnvironmentToHooks(p, environment))
: config.plugins
) as Plugin[]
// TODO: rework lib mode
const plugins = (libOptions ? config : environment).plugins.map((p) =>
injectEnvironmentToHooks(p, environment),
)

const rollupOptions: RollupOptions = {
preserveEntrySignatures: ssr
Expand Down Expand Up @@ -1396,6 +1396,14 @@ export class BuildEnvironment extends Environment {
}
super(name, config, options)
}

async init(): Promise<void> {
if (this._inited) {
return
}
this._inited = true
this._plugins = await resolveBoundedPlugins(this)
}
}

export interface ViteBuilder {
Expand Down Expand Up @@ -1504,6 +1512,9 @@ export async function createBuilder(
}

const environment = await createEnvironment(name, environmentConfig)

await environment.init()

environments[name] = environment
}

Expand Down

0 comments on commit a44810a

Please sign in to comment.