inject browser-polyfill only in chromium builds

This commit is contained in:
Thomas Rupprecht 2023-01-05 18:40:19 +01:00
parent b749f17f35
commit ae0c2ded1b
4 changed files with 16 additions and 5 deletions

View File

@ -30,7 +30,10 @@ Example: `npm run watch:firefox-android -- --firefox-apk=org.mozilla.fenix --fir
## Build
```ssh
$ npm run build
// For Firefox
$ npm run build:firefox
// For Chromium
$ npm run build:chromium
```
## Release

View File

@ -10,6 +10,8 @@
},
"scripts": {
"copy-browser-polyfill": "cp node_modules/webextension-polyfill/dist/browser-polyfill.js src/browser-polyfill.js",
"inject-browser-polyfill": "sed -i -r 's/(<!-- \\[INJECT-BROWSER-POLYFILL] -->).*/\\1<script type=\"module\" src=\"browser-polyfill.js\"><\\/script>/' src/*.html",
"uninject-browser-polyfill": "sed -i -r 's/(<!-- \\[INJECT-BROWSER-POLYFILL] -->).+/\\1/' src/*.html",
"copy-version": "sed -i 's/^\t\"version\": \".*\",$/\t\"version\": \"'$(rg '^\t\"version\": \"(.+)\",$' -r '$1' < package.json)'\",/' src/manifest.json",
"lint": "web-ext lint -w",
"test": "echo \"Error: no test specified\" && exit 0",
@ -17,12 +19,17 @@
"watch:firefox-android": "web-ext run -t firefox-android",
"watch:chromium": "web-ext run -t chromium",
"prebuild": "cp LICENSE.txt src/",
"build": "web-ext build",
"prebuild:firefox": "npm run prebuild",
"prebuild:chromium": "npm run prebuild && npm run inject-browser-polyfill",
"build:firefox": "web-ext build -i browser-polyfill.js",
"build:chromium": "web-ext build",
"postbuild": "rm src/LICENSE.txt",
"postbuild:firefox": "npm run postbuild",
"postbuild:chromium": "npm run postbuild && npm run uninject-browser-polyfill",
"postinstall": "npm run copy-browser-polyfill",
"preversion": "npm run lint && npm test",
"version": "npm run copy-version && git add -u",
"postversion": "npm run build"
"postversion": "npm run build:firefox"
},
"repository": {
"type": "git",

View File

@ -3,7 +3,8 @@
<head>
<meta charset="utf-8" />
<title>/usr/space</title>
<script type="module" src="browser-polyfill.js"></script>
<!-- [INJECT-BROWSER-POLYFILL] -->
<script type="module" src="background.js"></script>
</head>
</html>

View File

@ -88,7 +88,7 @@
</details>
</section>
<script type="module" src="browser-polyfill.js"></script>
<!-- [INJECT-BROWSER-POLYFILL] -->
<script type="module" src="popup.js"></script>
</body>
</html>