nuxt: Generate PWA Assets functionality not works when srcDir is not default
Hi team,
I’ve discovered an issue where the Generate PWA Assets functionality not works when the srcDir is not set to its default value (e.g: set to src).
I found the root cause in file: https://github.com/vite-pwa/vite-plugin-pwa/blob/6845dc7ab8c8927918a7431f4f8cb296dd399ca2/src/pwa-assets/config.ts#L64, the root is viteConfig.root and that is equal to nuxt.srcDir in nuxt default configuration. Therefore, if images are set to ‘src/public/favicon.svg’ in pwa-assets.config.ts, it resolves to ‘src/src/public/favicon.svg’. This results in a file not found error, as the actual path should be ‘src/public/favicon.svg’.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 2
- Comments: 15 (8 by maintainers)
resolve(nuxt.options.srcDir, options.dir)should correctly resolve toresolve(nuxt.options.rootDir, 'public')in this case.So… nuxt image not yet compatible with v4 layout
Nuxt resolves the public directory like this:
resolve(nuxt.options.srcDir, nuxt.options.dir.public).dir.publicispublicin v4 but will be a fully resolved directory in v4, defaulting toresolve(nuxt.options.rootDir, 'public').@userquin @danielroe minimal reproduction is here, but stackblitz can’t exec sharp, so I think should download this project and run at local
https://stackblitz.com/edit/reproduce-vite-pwa-nuxt-assets-custom-src-gwjm7u?file=README.md