- Notifications
You must be signed in to change notification settings - Fork0
A boilerplate template to get started making a react chrome extension
License
Moiz-CodeByte/boiler-plate-chrome-extension-react
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- This boilerplate adoptsManifest V3!
- For V2 users, please check out themanifest-v2 branch, or use version3.x.
- Check out theManifest V3 Migration Guide.
- Recently addeddevtools Support! ThanksGeekaholicLin!
- Recently updated fromReact
16to17! - Recently updated fromWebpack Dev Server
3.xto4.x andWebpack4to5! - Recently addedTypeScript Support!
This is a basic Chrome Extensions boilerplate to help you write modular and modern Javascript code, load CSS easily andautomatic reload the browser on code changes.
This boilerplate is updated with:
- Chrome Extension Manifest V3
- React 17
- Webpack 5
- Webpack Dev Server 4
- React Hot Loader
- eslint-config-react-app
- Prettier
- TypeScript
This boilerplate is heavily inspired by and adapted fromhttps://github.com/samuelsimoes/chrome-extension-webpack-boilerplate, with additional support for React 17 features, Webpack 5, and Webpack Dev Server 4.
Please open up an issue to nudge me to keep the npm packages up-to-date. FYI, it takes time to make different packages with different versions work together nicely.
- Check if yourNode.js version is >=14.
- Clone this repository.
- Change the package's
name,description, andrepositoryfields inpackage.json. - Change the name of your extension on
src/manifest.json. - Run
npm installto install the dependencies. - Run
npm start - Load your extension on Chrome following:
- Access
chrome://extensions/ - Check
Developer mode - Click on
Load unpacked extension - Select the
buildfolder.
- Access
- Happy hacking.
All your extension's code must be placed in thesrc folder.
The boilerplate is already prepared to have a popup, an options page, a background page, and a new tab page (which replaces the new tab page of your browser). But feel free to customize these.
This boilerplate now supports TypeScript! TheOptions Page is implemented using TypeScript. Please refer tosrc/pages/Options/ for example usages.
To make your workflow much more efficient this boilerplate uses thewebpack server to development (started withnpm start) with auto reload feature that reloads the browser automatically every time that you save some file in your editor.
You can run the dev mode on other port if you want. Just specify the env varport like this:
$ PORT=6002 npm run startAlthough this boilerplate uses the webpack dev server, it's also prepared to write all your bundles files on the disk at every code change, so you can point, on your extension manifest, to your bundles that you want to use ascontent scripts, but you need to exclude these entry points from hot reloading(why?). To do so you need to expose which entry points are content scripts on thewebpack.config.js using thechromeExtensionBoilerplate -> notHotReload config. Look the example below.
Let's say that you want use themyContentScript entry point as content script, so on yourwebpack.config.js you will configure the entry point and exclude it from hot reloading, like this:
{… entry:{myContentScript:"./src/js/myContentScript.js"},chromeExtensionBoilerplate:{notHotReload:["myContentScript"]}…}
and on yoursrc/manifest.json:
{"content_scripts": [ {"matches": ["https://www.google.com/*"],"js": ["myContentScript.bundle.js"] } ]}Thanks to@hudidit's kind suggestions, this boilerplate supports chrome-specific intelligent code completion using@types/chrome.
After the development of your extension run the command
$ NODE_ENV=production npm run buildNow, the content ofbuild folder will be the extension ready to be submitted to the Chrome Web Store. Just take a look at theofficial guide to more infos about publishing.
If you are developing an extension that talks with some API you probably are using different keys for testing and production. Is a good practice you not commit your secret keys and expose to anyone that have access to the repository.
To this task this boilerplate import the file./secrets.<THE-NODE_ENV>.js on your modules through the module named assecrets, so you can do things like this:
./secrets.development.js
exportdefault{key:'123'};
./src/popup.js
importsecretsfrom'secrets';ApiCall({key:secrets.key});
👉 The files with namesecrets.*.js already are ignored on the repository.
Michael Xieyang Liu |Website
About
A boilerplate template to get started making a react chrome extension
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.