Skip to content

fix: emit manifest.webmanifest relative to custom outDir#934

Closed
jack-old-archive wants to merge 2 commits into
vite-pwa:mainfrom
jack-old-archive:fix/manifest-outdir
Closed

fix: emit manifest.webmanifest relative to custom outDir#934
jack-old-archive wants to merge 2 commits into
vite-pwa:mainfrom
jack-old-archive:fix/manifest-outdir

Conversation

@jack-old-archive

Copy link
Copy Markdown

Summary

Fixes #919.

Problem

When configuring a custom outDir (e.g., outDir: 'dist/client/_pwa'), the service worker (sw.js) and icons were correctly placed inside the _pwa directory. However, manifest.webmanifest was always generated in the root of the build output (e.g., dist/client/manifest.webmanifest), ignoring the outDir option.

Solution

Calculate the relative path from the main Vite build output directory to the PWA custom output directory, and use this relative path when emitting the manifest file via emitFile.

Changes

  • src/api.ts:
    • Added join and relative to imports.
    • Updated _generateBundle to compute manifestFileName based on the relative subdirectory between the Vite build.outDir and the PWA outDir.

Verification

Using the configuration:

VitePWA({

  outDir: 'dist/client/_pwa',

  buildBase: '/_pwa/'

})
## Before:
* `dist/client/manifest.webmanifest` (Incorrect location)
*  `dist/client/_pwa/sw.js` 
## After: 
* `dist/client/_pwa/manifest.webmanifest` (Correct location)
*  `dist/client/_pwa/sw.js` 

Closes #919. The manifest file was always emitted to the root of the main
Vite build output, ignoring the custom  option. This fix calculates
the relative subdirectory and emits the manifest correctly alongside other
PWA assets like sw.js and icons.'
@netlify

netlify Bot commented May 17, 2026

Copy link
Copy Markdown

Deploy Preview for vite-plugin-pwa-legacy failed.

Name Link
🔨 Latest commit 617b7fd
🔍 Latest deploy log https://app.netlify.com/projects/vite-plugin-pwa-legacy/deploys/6a09baa590bd660008f38988

@jack-old-archive jack-old-archive closed this by deleting the head repository May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: unexpected behaviour when using outDir and buildBase

1 participant