A Cross-platform React TS starter for browser extensions.
This template is prepared for making cross-platform extension
development in a single React Project with ease. It is also using a browser
polyfill to match the API codebase and use them as Promises. During the
development you can build your extension automatically via WebPack and
thanks to web-ext
it can reload it by watching the changes.
There are a couple of problems when we decide to develop an extension for the most common browsers:
- We cannot use Manifest V3 yet in Firefox except by turning on the developer preview manually. see here.
- All the Chrome APIs do not yet support Promise-based approaches.
- During the development, we need to reload extension every time we update the codes.
- Packing the bundles and getting the extension ready for publishing can be time-consuming.
- Already installed Firefox or Chrome browser
- node + npm
- web-ext (Included as dependency of it's webpack extension)
- TypeScript
- Webpack
- React
- Jest
- Example Code Includes:
- background.js
- Options page
- Content script
- Pop-up
- Storage API
- Tabs API
- WebExtension browser API Polyfill
- web-ext & Its WebPack Plugin
/react-ts-starter-for-extensions
├── dist
│ ├── js # Generated code bundles
│ └── ...
├── public
│ └── ... # Static files
├── src
│ ├── __tests__ # Jest tests folder
│ ├── types # TS Types folder
│ ├── utils # Utility codes folder
│ ├── background.ts # Extension's background file
│ ├── content_script.ts # The script will be injected to the page
│ ├── options.ts # Extension's settings page
│ └── popup.ts # Extension's pop-up page
├── webpack
│ ├── webpack.common.js # Common tasks
│ ├── webpack.dev.js # Dev related tasks
│ └── webpack.prod.js # Prod related tasks
...
Feel free to remove the parts that you do not need and then edit the webpack config files.
Press "Use this template" button above and then clone the project on your local.
npm install
npm run watch
npm run watch:c
npm run build
npm run build:c
npm run clean
npm run test
To further testing, you might want to have a look at mockzilla.
You might want to check out web-ext
CLI documentation in order to experience
further settings. You can run the extension with any version of browsers,
or passing different folder setups. You can even test Manifest V3 on Firefox by
passing firefoxPreview
option with'mv3'
value on webpack config.
- For inspiring me, @chibat
- For making this possible via amazing tools, Mozilla's Teams and Contributors
- For automatizing, WebPack
If you ever think that something useful can be added, please do not hesitate to open a PR with a new branch.
You can always text me via Twitter DM.