feat(webpack): introduce webpack:configResolved hook (#20412)

This commit is contained in:
Anthony Fu 2023-04-30 00:37:29 +02:00 committed by GitHub
parent 17ca50354b
commit cd7f38988a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -75,6 +75,7 @@ Hook | Arguments | Description
`vite:serverCreated` | `viteServer, env` | Called when the Vite server is created.
`vite:compiled` | - | Called after Vite server is compiled.
`webpack:config` | `webpackConfigs` | Called before configuring the webpack compiler.
`webpack:configResolved` | `webpackConfigs` | Allows to read the resolved webpack config.
`webpack:compile` | `options` | Called right before compilation.
`webpack:compiled` | `options` | Called after resources are loaded.
`webpack:change` | `shortPath` | Called on `change` on WebpackBar.

View File

@ -317,6 +317,12 @@ export interface NuxtHooks {
* @returns Promise
*/
'webpack:config': (webpackConfigs: Configuration[]) => HookResult
/**
* Allows to read the resolved webpack config
* @param webpackConfigs Configs objects to be pushed to the compiler
* @returns Promise
*/
'webpack:configResolved': (webpackConfigs: Readonly<Configuration>[]) => HookResult
/**
* Called right before compilation.
* @param options The options to be added

View File

@ -35,8 +35,7 @@ export async function bundle (nuxt: Nuxt) {
// Initialize shared MFS for dev
const mfs = nuxt.options.dev ? createMFS() : null
// Configure compilers
const compilers = webpackConfigs.map((config) => {
for (const config of webpackConfigs) {
config.plugins!.push(DynamicBasePlugin.webpack({
sourcemap: nuxt.options.sourcemap[config.name as 'client' | 'server']
}))
@ -49,7 +48,12 @@ export async function bundle (nuxt: Nuxt) {
rootDir: nuxt.options.rootDir,
composables: nuxt.options.optimization.keyedComposables
}))
}
await nuxt.callHook('webpack:configResolved', webpackConfigs)
// Configure compilers
const compilers = webpackConfigs.map((config) => {
// Create compiler
const compiler = webpack(config)