@magic-works/webextension-systemjs
v0.0.4
Published
A SystemJS loader for Web Extension content script
Downloads
2
Readme
Use SystemJS in content script of Web Extension
Motivation
To use ES Module in Web Extension.
But it is blocked by Firefox Bug 1536094: Dynamic module import doesn't work in webextension content scripts
Perquisite
If not running on the Firefox, you have to include a polyfill: webextension-polyfill.
- Build all your code into
ESModule
format andSystemJS
format.
Usage
- Install
@magic-works/webextension-systemjs
- Load
@magic-works/webextension-systemjs/background-script.js
in the background script - Load
@magic-works/webextension-systemjs/content-script.js
before your code. - Transpile all your code into SystemJS format.
- Run you content script by
// Chrome support native ES Module in content script
import(browser.runtime.getURL("./es/content-script.js")).catch(() => {
// Firefox fallback to SystemJS
System.import("./system/content-script.js")
})
An example repo
https://github.com/Jack-Works/web-extension-esmodule-test/tree/master/mixed