Skip to content

Commit

Permalink
build(wxt): avoid duplicate content scripts entries during build (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter authored Jul 12, 2024
1 parent 500cbb1 commit 8ff7fcf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/entries/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { flavor } from '@/storage';
import { injectStyles, replaceIconInRow } from './lib';

export default defineContentScript({
// Make sure this value is updated in wxt.config.ts as well.
// Make sure `matches` URLs are updated in wxt.config.ts as well.
matches: ['*://github.com/*', '*://gitlab.com/*', '*://codeberg.org/*'],
runAt: 'document_start',

Expand Down
26 changes: 18 additions & 8 deletions wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ export default defineConfig({
permissions: ['storage', 'scripting', 'contextMenus', 'activeTab'],
// @ts-expect-error: Now in browsers (see https://github.com/w3c/webextensions/issues/119).
optional_host_permissions: ['*://*/*'],
// Make sure to update in src/entries/content/index.ts as well.
content_scripts: [
{
matches: ['*://codeberg.org/*', '*://github.com/*', '*://gitlab.com/*'],
run_at: 'document_start',
js: ['content-scripts/content.js'],
},
],
homepage_url: 'https://github.com/catppuccin/github-file-explorer-icons',
},
hooks: {
Expand Down Expand Up @@ -59,6 +51,24 @@ export default defineConfig({
),
);
},
'build:manifestGenerated': (wxt, manifest) => {
if (wxt.config.command === 'serve') {
// During development, content script is not listed in manifest, causing
// "webext-dynamic-content-scripts" to throw an error. So we need to
// add it manually.
manifest.content_scripts ??= [];
manifest.content_scripts.push({
// Make sure `matches` URLs are updated in src/entries/content/index.ts as well.
matches: [
'*://github.com/*',
'*://gitlab.com/*',
'*://codeberg.org/*',
],
run_at: 'document_start',
js: ['content-scripts/content.js'],
});
}
},
},
runner: {
startUrls: [
Expand Down

0 comments on commit 8ff7fcf

Please sign in to comment.