ES Module for Web Extensions

TLDR:

It is pretty easy if you’re using manifest v2 🎇 after 2021/05/18 (Firefox 89 release).

For background page, popup, ..etc:

1
<script type="module" src="./background.js"></script>

For content scripts:

1
2
import(chrome.runtime.getURL('...'))
import(browser.runtime.getURL('...'))
Read more