[v2.0.0] Custom image dir duplicated to public output during generate (ipx/ipxStatic)
Describe the bug
When using @nuxt/image v2 with a custom dir configuration (e.g., assets/media), the entire source directory is automatically copied to the .output/public folder during nuxt generate / prerendering.
This happens with both ipx and ipxStatic providers.
It appears that v2.0.0 automatically registers the configured dir into Nitro's publicAssets list. This forces Nitro to copy the raw source files to the distribution folder, resulting in build bloat and exposing source assets that should remain internal.
Environment
- OS: Windows 10 (WSL / Ubuntu 24.04)
- Node: v23.10
- Package Manager: pnpm 10.19.0
- Nuxt: v4.2.1
- @nuxt/image: v2.0.0
Reproduction
- Initialize a fresh Nuxt project.
- Create a source directory:
assets/mediaand place a large image file inside. - Configure
nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxt/image'],
image: {
dir: 'assets/media',
provider: 'ipxStatic' // Reproducible with 'ipx' as well
}
})
- Run
pnpm run generate. - Inspect the
.output/publicdirectory.
Expected behavior
The output directory should only contain the optimized _ipx folder (and generated app files). The raw source folder (assets/media) should NOT be copied to the public output.
Actual behavior The output directory contains both:
- The optimized images in
_ipx/ - The contents of the source directory are copied to the root of the public output directory (e.g., source
assets/media/folder/img.jpgbecomes.output/public/folder/img.jpg).
Workaround
A nitro:init hook can be used to manually filter out the source directory from Nitro's public assets list before the build starts.
export default defineNuxtConfig({
hooks: {
'nitro:init'(nitro) {
nitro.options.publicAssets = nitro.options.publicAssets.filter(
(asset) => !asset.dir?.includes('assets/media')
)
}
}
})