Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: non-determinstic options page generation #137

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion options.html

This file was deleted.

2 changes: 1 addition & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const manifest = defineManifest(async () => ({
name: `${packageJson.displayName ?? packageJson.name}${mode === 'development' ? ' (dev)' : ''}`,
version: `${major}.${minor}.${patch}.${label}`,
description: packageJson.description,
options_page: 'options.html',
options_page: 'src/pages/options/index.html',
background: { service_worker: 'src/pages/background/background.ts' },
permissions: ['storage', 'unlimitedStorage', 'background', 'scripting'],
host_permissions: process.env.MODE === 'development' ? [...HOST_PERMISSIONS, '<all_urls>'] : HOST_PERMISSIONS,
Expand Down
19 changes: 19 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ const renameFile = (source: string, destination: string): Plugin => {
};
};

const fixManifestOptionsPage = () => ({
name: 'fix-manifest-options-page',
apply: 'build' as const,
enforce: 'post' as const,
generateBundle(_, bundle) {
for (const fileName of Object.keys(bundle)) {
if (fileName.startsWith('assets/crx-manifest')) {
const chunk = bundle[fileName];
chunk.code = chunk.code.replace(
/"options_page":"src\/pages\/options\/index.html"/,
`"options_page":"options.html"`
);
break;
}
}
},
});

let config: ResolvedConfig;
let server: ViteDevServer;

Expand All @@ -52,6 +70,7 @@ export default defineConfig({
UnoCSS(),
Icons({ compiler: 'jsx', jsx: 'react' }),
crx({ manifest }),
fixManifestOptionsPage(),
inspect(),
{
name: 'public-transform',
Expand Down
Loading