image icon indicating copy to clipboard operation
image copied to clipboard

[v2.0.0] Custom image dir duplicated to public output during generate (ipx/ipxStatic)

Open whooisdev opened this issue 5 months ago • 0 comments

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

  1. Initialize a fresh Nuxt project.
  2. Create a source directory: assets/media and place a large image file inside.
  3. Configure nuxt.config.ts:
export default defineNuxtConfig({
  modules: ['@nuxt/image'],
  image: {
    dir: 'assets/media',
    provider: 'ipxStatic' // Reproducible with 'ipx' as well
  }
})
  1. Run pnpm run generate.
  2. Inspect the .output/public directory.

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:

  1. The optimized images in _ipx/
  2. The contents of the source directory are copied to the root of the public output directory (e.g., source assets/media/folder/img.jpg becomes .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')
      )
    }
  }
})

whooisdev avatar Nov 22 '25 09:11 whooisdev