Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@userquin
Copy link
Member

@userquin userquin commented Oct 17, 2025

Description

The PWA Assets configuration will be loaded twice, from the module to generate the DTS files and then from vite-plugin-pwa to generate the PWA icons, web manifest and releated stuff.

This PR changes the logic in the module to resolve the images always from rootDir, srcDir and publicDir (in this order). If using inlined configuration at the Nuxt config. file, then, the new logic will also change the configuration to use the relative path from srcDir since vite-plugin-pwa will use vite.root to resolve the images.

This PR forces to use always vite.root when using Nuxt v3 v4 compat mode or Nuxt v4 (app folder) to resolve pwa images when using pwa-assets.config.ts at root or inside the app folder, there is no way to resolve this issue since there is no way to change the logic from this integration (not yet, maybe in a future).

Nuxt 3:

  • if inlined configuration, can use public/<icon-name> (recommend) or just <icon-name>
  • if config enabled using pwa-assets.config.ts, can only use public/<icon-name>

Nuxt 3 v4 compat mode or Nuxt v4+:

  • if inlined configuration, can use public/<icon-name> (recomended), ../public/<icon-name> or <icon-name>
  • if config enabled using pwa-assets.config.ts (at root) or app/pwa-assets.config.ts, the image can be relative to the file or the rootDir: can use public/<icon-name> (recomended) or ../public/<icon-name>
  • if config enabled using app/pwa-assets.config.ts, the image can be relative to the file or the rootDir: can only use ../public/<icon-name>

Linked Issues

resolves #204
resolves #210
resolves #211
superdeses #207

Additional Context

About WebStorm/IntelliJ and Nuxt 4

Now WebStorm not working with Nuxt 4, auto completion is not working for PWAXXX components in the template, tried also with the new Vue LS 3.0 Preview with and wihout these dependencies, no way (also tried with and without dts on nodeReferences, this PR including them when Nuxt 4 detected):

"devDependencies": {
    "@types/node": "^24.8.1",
    "@vue/language-server": "^3.1.1",
    "@vue/language-service": "^3.1.1",
    "typescript": "~5.9.3",
    "vue-tsc": "^3.1.1"
  },

https://youtrack.jetbrains.com/issue/WEB-74161/weird-behavior

/cc @danielroe @niklas-wortmann (I'm out of ideas, VSCode working correctly)


Tip

The author of this PR can publish a preview release by commenting /publish below.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 17, 2025

npm i https://pkg.pr.new/@vite-pwa/nuxt@218

commit: 337f4bd

@userquin userquin changed the title fix(pwa-assets): resolve image always relative to root folder fix(pwa-assets): resolve image always relative to app folder Oct 17, 2025
@userquin userquin changed the title fix(pwa-assets): resolve image always relative to app folder fix(pwa-assets): resolve image always relative to vite.root Oct 17, 2025
@userquin userquin marked this pull request as draft October 17, 2025 21:14
@userquin userquin marked this pull request as ready for review October 18, 2025 01:02
@userquin userquin marked this pull request as draft October 18, 2025 01:50
@userquin userquin marked this pull request as ready for review October 18, 2025 02:03
@userquin userquin requested a review from Copilot October 18, 2025 02:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes PWA asset image resolution to always use paths relative to vite.root, addressing issues where images couldn't be resolved consistently across different Nuxt configurations and directory structures.

  • Introduces a new NuxtPWAContext type to centralize configuration and context data
  • Implements a more robust image resolution strategy that tries multiple directories (rootDir, srcDir, publicDir) in order
  • Updates the PWA assets configuration to use relative paths from srcDir for consistency with vite-plugin-pwa

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/context.ts Adds new NuxtPWAContext interface to centralize PWA configuration context
src/utils/pwa-icons.ts Refactors image resolution logic to try multiple directories and always resolve relative to vite.root
src/utils/pwa-icons-types.ts Updates function signature to use new context parameter
src/utils/module.ts Creates and passes context object instead of individual parameters
src/utils/config.ts Updates function signature to use context parameter
playground-assets/nuxt.config.ts Adds commented configuration options for testing
playground-assets/.nuxtrc Adds TypeScript configuration exclusion
package.json Adds new development scripts for playground-assets

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@userquin userquin merged commit 50614f7 into main Oct 18, 2025
1 check failed
@userquin userquin deleted the userquin/fix-pwa-assets-logic branch October 18, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants