nuxt
nuxt copied to clipboard
`build:compile` Nuxt hook seems to not being triggered correctly
Version
Reproduction link
https://github.com/kevinmarrec/nuxt-build-compile-hook-issue
Steps to reproduce
Clone the reproduction link repository
Install deps : yarn
or npm install
Run in dev mode : yarn dev
or npm run dev
Look at the ~/modules/test
module, it's gonna output a compile
on the therminal when the build:compile
hook is triggered.
Change one or multiple times the ~pages/index.vue
to trigger a new Webpack compilation through the Hot Reload Module.
What is expected ?
build:compile
hook should be triggered at every Webpack compilation
What is actually happening?
build:compile
hook is triggered only once (in fact twice but one for server, one for client) at the first compilation, and never for further Webpack compilations.
Additional comments?
See : https://github.com/nuxt/nuxt.js/blob/dev/packages/webpack/src/builder.js#L129
I suggest replacing this line by something similar done for the build:compiled
hook, e.g. using the Webpack Compiler hook callback itself.
See : https://webpack.js.org/api/compiler-hooks/#compile
So it could be something like
compiler.hooks.compile.tap('???', async () => {
await nuxt.callHook('build:compile', { name, compiler }
})