Skip to content

Commit 22fbb25

Browse files
added base for wallet chrome extension
0 parents  commit 22fbb25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+30812
-0
lines changed

.babelrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
// "@babel/preset-env",
4+
// "@babel/preset-react"
5+
"react-app"
6+
],
7+
"plugins": [
8+
// "@babel/plugin-proposal-class-properties",
9+
"react-hot-loader/babel"
10+
]
11+
}

.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "react-app",
3+
"globals": {
4+
"chrome": "readonly"
5+
}
6+
}

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/build
11+
12+
# misc
13+
.DS_Store
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
.history
19+
20+
# secrets
21+
secrets.*.js

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v15.4.0

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"requirePragma": false,
5+
"arrowParens": "always"
6+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Michael Xieyang Liu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<img src="src/assets/img/icon-128.png" width="64"/>
2+
3+
# Chrome Extension Boilerplate with React 17 and Webpack 5
4+
5+
[![npm](https://img.shields.io/npm/v/chrome-extension-boilerplate-react)](https://www.npmjs.com/package/chrome-extension-boilerplate-react)
6+
[![npm-download](https://img.shields.io/npm/dw/chrome-extension-boilerplate-react)](https://www.npmjs.com/package/chrome-extension-boilerplate-react)
7+
[![npm](https://img.shields.io/npm/dm/chrome-extension-boilerplate-react)](https://www.npmjs.com/package/chrome-extension-boilerplate-react)
8+
9+
[![dependencies Status](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react/status.svg)](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react)
10+
[![devDependencies Status](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react/dev-status.svg)](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react?type=dev)
11+
12+
## Announcements
13+
14+
- **_This boilerplate adopts [Manifest V3](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/)!_** For V2 users, please check out the [manifest-v2](https://github.com/lxieyang/chrome-extension-boilerplate-react/tree/manifest-v2) branch, or use version [3.x](https://www.npmjs.com/package/chrome-extension-boilerplate-react/v/3.3.0).
15+
- Check out the [Manifest V3 Migration Guide](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/).
16+
- Recently added [devtools](https://developer.chrome.com/docs/extensions/mv3/devtools/) Support! Thanks [GeekaholicLin](https://github.com/lxieyang/chrome-extension-boilerplate-react/issues/17)!
17+
- Recently updated from React ~~16~~ to **17** and Webpack ~~4~~ to **5**!
18+
- Recently added [TypeScript](https://www.typescriptlang.org/) Support!
19+
20+
## Features
21+
22+
This is a basic Chrome Extensions boilerplate to help you write modular and modern Javascript code, load CSS easily and [automatic reload the browser on code changes](https://webpack.github.io/docs/webpack-dev-server.html#automatic-refresh).
23+
24+
This boilerplate is updated with:
25+
26+
- [Chrome Extension Manifest V3](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/)
27+
- [React 17](https://reactjs.org)
28+
- [Webpack 5](https://webpack.js.org/)
29+
- [React Hot Loader](https://github.com/gaearon/react-hot-loader)
30+
- [eslint-config-react-app](https://www.npmjs.com/package/eslint-config-react-app)
31+
- [Prettier](https://prettier.io/)
32+
- [TypeScript](https://www.typescriptlang.org/)
33+
34+
This boilerplate is heavily inspired by and adapted from [https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate), with additional support for React 17 features and Webpack 5.
35+
36+
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.
37+
38+
## Installing and Running
39+
40+
### Procedures:
41+
42+
1. Check if your [Node.js](https://nodejs.org/) version is >= **14**.
43+
2. Clone this repository.
44+
3. Change the package's `name`, `description`, and `repository` fields in `package.json`.
45+
4. Change the name of your extension on `src/manifest.json`.
46+
5. Run `npm install` to install the dependencies.
47+
6. Run `npm start`
48+
7. Load your extension on Chrome following:
49+
1. Access `chrome://extensions/`
50+
2. Check `Developer mode`
51+
3. Click on `Load unpacked extension`
52+
4. Select the `build` folder.
53+
8. Happy hacking.
54+
55+
## Structure
56+
57+
All your extension's code must be placed in the `src` folder.
58+
59+
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.
60+
61+
## TypeScript
62+
63+
This boilerplate now supports TypeScript! The `Options` Page is implemented using TypeScript. Please refer to `src/pages/Options/` for example usages.
64+
65+
## Webpack auto-reload and HRM
66+
67+
To make your workflow much more efficient this boilerplate uses the [webpack server](https://webpack.github.io/docs/webpack-dev-server.html) to development (started with `npm start`) with auto reload feature that reloads the browser automatically every time that you save some file in your editor.
68+
69+
You can run the dev mode on other port if you want. Just specify the env var `port` like this:
70+
71+
```
72+
$ PORT=6002 npm run start
73+
```
74+
75+
## Content Scripts
76+
77+
Although 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 as [content scripts](https://developer.chrome.com/extensions/content_scripts), but you need to exclude these entry points from hot reloading [(why?)](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/issues/4#issuecomment-261788690). To do so you need to expose which entry points are content scripts on the `webpack.config.js` using the `chromeExtensionBoilerplate -> notHotReload` config. Look the example below.
78+
79+
Let's say that you want use the `myContentScript` entry point as content script, so on your `webpack.config.js` you will configure the entry point and exclude it from hot reloading, like this:
80+
81+
```js
82+
{
83+
84+
entry: {
85+
myContentScript: "./src/js/myContentScript.js"
86+
},
87+
chromeExtensionBoilerplate: {
88+
notHotReload: ["myContentScript"]
89+
}
90+
91+
}
92+
```
93+
94+
and on your `src/manifest.json`:
95+
96+
```json
97+
{
98+
"content_scripts": [
99+
{
100+
"matches": ["https://www.google.com/*"],
101+
"js": ["myContentScript.bundle.js"]
102+
}
103+
]
104+
}
105+
```
106+
107+
## Intelligent Code Completion
108+
109+
Thanks to [@hudidit](https://github.com/lxieyang/chrome-extension-boilerplate-react/issues/4)'s kind suggestions, this boilerplate supports chrome-specific intelligent code completion using [@types/chrome](https://www.npmjs.com/package/@types/chrome). For example:
110+
111+
![intellisense](https://lxieyang.github.io/static/chrome-extension-boilerplate-dev-intellisense-ed9e7c485d3eaf66417e5da4748e2c97.png)
112+
113+
## Packing
114+
115+
After the development of your extension run the command
116+
117+
```
118+
$ NODE_ENV=production npm run build
119+
```
120+
121+
Now, the content of `build` folder will be the extension ready to be submitted to the Chrome Web Store. Just take a look at the [official guide](https://developer.chrome.com/webstore/publish) to more infos about publishing.
122+
123+
## Secrets
124+
125+
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.
126+
127+
To this task this boilerplate import the file `./secrets.<THE-NODE_ENV>.js` on your modules through the module named as `secrets`, so you can do things like this:
128+
129+
_./secrets.development.js_
130+
131+
```js
132+
export default { key: '123' };
133+
```
134+
135+
_./src/popup.js_
136+
137+
```js
138+
import secrets from 'secrets';
139+
ApiCall({ key: secrets.key });
140+
```
141+
142+
:point_right: The files with name `secrets.*.js` already are ignored on the repository.
143+
144+
## Resources:
145+
146+
- [Webpack documentation](https://webpack.js.org/concepts/)
147+
- [Chrome Extension documentation](https://developer.chrome.com/extensions/getstarted)
148+
149+
---
150+
151+
Michael Xieyang Liu | [Website](https://lxieyang.github.io)

0 commit comments

Comments
 (0)