diff --git a/.changeset/yellow-paws-search.md b/.changeset/yellow-paws-search.md new file mode 100644 index 000000000..9c4d58b35 --- /dev/null +++ b/.changeset/yellow-paws-search.md @@ -0,0 +1,6 @@ +--- +'@crxjs/vite-plugin': patch +--- + +Vite 5 moved vite manifest from 'manifest.json' to '.vite/manifest.json'. +This change updates the plugin to use the new location if Vite major version is >4, old location otherwise. \ No newline at end of file diff --git a/packages/vite-plugin/src/node/plugin-webAccessibleResources.ts b/packages/vite-plugin/src/node/plugin-webAccessibleResources.ts index 3a1311145..3306d8ce2 100644 --- a/packages/vite-plugin/src/node/plugin-webAccessibleResources.ts +++ b/packages/vite-plugin/src/node/plugin-webAccessibleResources.ts @@ -1,5 +1,9 @@ import { OutputChunk } from 'rollup' -import { Manifest as ViteManifest, ResolvedConfig } from 'vite' +import { + Manifest as ViteManifest, + ResolvedConfig, + version as ViteVersion, +} from 'vite' import { compileFileResources } from './compileFileResources' import { contentScripts } from './contentScripts' import { DYNAMIC_RESOURCE } from './defineManifest' @@ -102,10 +106,16 @@ export const pluginWebAccessibleResources: CrxPluginFn = () => { // derive content script resources from vite file manifest if (contentScripts.size > 0) { + // Vite 5 changed the manifest.json location to .vite/manifest.json. + // In order to support both Vite <=4 and Vite 5, we need to check the Vite version and determine the path accordingly. + const viteMajorVersion = parseInt(ViteVersion.split('.')[0]) + const manifestPath = viteMajorVersion > 4 ? '.vite/manifest.json' : 'manifest.json' + const viteManifest = parseJsonAsset( bundle, - 'manifest.json', + manifestPath, ) + const viteFiles = new Map() for (const [, file] of Object.entries(viteManifest)) viteFiles.set(file.file, file)