-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
@wxt-dev/webextension-polyfill
module (#1310)
- Loading branch information
Showing
14 changed files
with
342 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ on: | |
- module-vue | ||
- storage | ||
- unocss | ||
- webextension-polyfill | ||
- wxt | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ on: | |
- module-svelte | ||
- module-vue | ||
- storage | ||
- webextension-polyfill | ||
- wxt | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# `@wxt-dev/webextension-polyfill` | ||
|
||
Configures `wxt/browser` to import `browser` from [`webextension-polyfill`](https://github.com/mozilla/webextension-polyfill) instead of using the regular `chrome`/`browser` globals WXT normally provides. | ||
|
||
## Usage | ||
|
||
```sh | ||
pnpm i @wxt-dev/webextension-polyfill webextension-polyfill | ||
``` | ||
|
||
Then add the module to your config: | ||
|
||
```ts | ||
// wxt.config.ts | ||
export default defineConfig({ | ||
modules: ['@wxt-dev/webextension-polyfill'], | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { defineBuildConfig } from 'unbuild'; | ||
import { resolve } from 'node:path'; | ||
|
||
export default defineBuildConfig({ | ||
rootDir: 'modules', | ||
outDir: resolve(__dirname, 'dist'), | ||
entries: [ | ||
{ input: 'webextension-polyfill/index.ts', name: 'index' }, | ||
{ input: 'webextension-polyfill/browser.ts', name: 'browser' }, | ||
], | ||
replace: { | ||
'process.env.NPM': 'true', | ||
}, | ||
declaration: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default defineContentScript({ | ||
matches: ['*://*/*'], | ||
async main() { | ||
console.log(browser.runtime.id); | ||
}, | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/webextension-polyfill/entrypoints/popup/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./main.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const root = document.getElementById('app')!; | ||
|
||
root.textContent = browser.runtime.id; |
1 change: 1 addition & 0 deletions
1
packages/webextension-polyfill/modules/webextension-polyfill/browser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as browser } from 'webextension-polyfill'; |
18 changes: 18 additions & 0 deletions
18
packages/webextension-polyfill/modules/webextension-polyfill/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'wxt'; | ||
import { addViteConfig, defineWxtModule } from 'wxt/modules'; | ||
import { resolve } from 'node:path'; | ||
|
||
export default defineWxtModule({ | ||
name: '@wxt-dev/webextension-polyfill', | ||
setup(wxt) { | ||
addViteConfig(wxt, () => ({ | ||
resolve: { | ||
alias: { | ||
'wxt/browser': process.env.NPM | ||
? '@wxt-dev/webextension-polyfill/browser' | ||
: resolve(__dirname, 'browser.ts'), | ||
}, | ||
}, | ||
})); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "@wxt-dev/webextension-polyfill", | ||
"description": "Use webextension-polyfill with WXT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wxt-dev/wxt.git", | ||
"directory": "packages/webextension-polyfill" | ||
}, | ||
"homepage": "https://github.com/wxt-dev/wxt/blob/main/packages/webextension-polyfill/README.md", | ||
"keywords": [ | ||
"wxt", | ||
"module", | ||
"webextension-polyfill" | ||
], | ||
"author": { | ||
"name": "Aaron Klinker", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"main": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"./browser": { | ||
"types": "./dist/browser.d.mts", | ||
"default": "./dist/browser.mjs" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"dev": "wxt", | ||
"check": "pnpm build && check", | ||
"build": "buildc -- unbuild", | ||
"prepare": "buildc --deps-only -- wxt prepare" | ||
}, | ||
"peerDependencies": { | ||
"webextension-polyfill": "*", | ||
"wxt": ">=0.20.0" | ||
}, | ||
"devDependencies": { | ||
"@aklinker1/check": "^1.4.5", | ||
"@types/webextension-polyfill": "^0.12.1", | ||
"publint": "^0.2.12", | ||
"typescript": "^5.6.3", | ||
"unbuild": "^2.0.0", | ||
"webextension-polyfill": "^0.12.0", | ||
"wxt": "workspace:*" | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": ["../../tsconfig.base.json", "./.wxt/tsconfig.json"], | ||
"exclude": ["node_modules/**", "dist/**"] | ||
} |
Oops, something went wrong.