Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.

Commit 1d6c1da

Browse files
committed
Initial implementation
0 parents  commit 1d6c1da

32 files changed

+4708
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
build
3+
secrets.*.js

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Samuel Simões
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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Chrome Extension Webpack Boilerplate
2+
3+
A basic foundation boilerplate for rich Chrome Extensions using [Webpack](https://webpack.github.io/) 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).
4+
5+
## Developing a new extension
6+
_I'll assume that you already read the [Webpack docs](https://webpack.github.io/docs) and the [Chrome Extension](https://developer.chrome.com/extensions/getstarted) docs._
7+
8+
1. Clone the repository.
9+
2. Install [yarn](https://yarnpkg.com): `npm install -g yarn`.
10+
3. Run `yarn`.
11+
4. Change the package's name and description on `package.json`.
12+
5. Change the name of your extension on `src/manifest.json`.
13+
6. Run `npm run start`
14+
7. Load your extension on Chrome following:
15+
1. Access `chrome://extensions/`
16+
2. Check `Developer mode`
17+
3. Click on `Load unpacked extension`
18+
4. Select the `build` folder.
19+
8. Have fun.
20+
21+
## Structure
22+
All your extension's development code must be placed in `src` folder, including the extension manifest.
23+
24+
The boilerplate is already prepared to have a popup, a options page and a background page. You can easily customize this.
25+
26+
Each page has its own [assets package defined](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/blob/master/webpack.config.js#L16-L20). So, to code on popup you must start your code on `src/js/popup.js`, for example.
27+
28+
You must use the [ES6 modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) to a better code organization. The boilerplate is already prepared to that and [here you have a little example](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/blob/master/src/js/popup.js#L2-L4).
29+
30+
## Webpack auto-reload and HRM
31+
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 run server`) with auto reload feature that reloads the browser automatically every time that you save some file o your editor.
32+
33+
You can run the dev mode on other port if you want. Just specify the env var `port` like this:
34+
35+
```
36+
$ PORT=6002 npm run start
37+
```
38+
39+
## Content Scripts
40+
41+
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.
42+
43+
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:
44+
45+
```js
46+
{
47+
48+
entry: {
49+
myContentScript: "./src/js/myContentScript.js"
50+
},
51+
chromeExtensionBoilerplate: {
52+
notHotReload: ["myContentScript"]
53+
}
54+
55+
}
56+
```
57+
58+
and on your `src/manifest.json`:
59+
60+
```json
61+
{
62+
"content_scripts": [
63+
{
64+
"matches": ["https://www.google.com/*"],
65+
"js": ["myContentScript.bundle.js"]
66+
}
67+
]
68+
}
69+
70+
```
71+
72+
## Packing
73+
After the development of your extension run the command
74+
75+
```
76+
$ NODE_ENV=production npm run build
77+
```
78+
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.
79+
80+
## Secrets
81+
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.
82+
83+
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:
84+
85+
_./secrets.development.js_
86+
87+
```js
88+
export default { key: "123" };
89+
```
90+
91+
_./src/popup.js_
92+
93+
```js
94+
import secrets from "secrets";
95+
ApiCall({ key: secrets.key });
96+
```
97+
:point_right: The files with name `secrets.*.js` already are ignored on the repository.
98+
99+
## With React.js
100+
:bulb: If you want use [React.js](https://facebook.github.io/react/) with this boilerplate, check the **[react branch](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/tree/react)**.
101+
102+
-------------
103+
Samuel Simões ~ [@samuelsimoes](https://twitter.com/samuelsimoes) ~ [Blog](http://blog.samuelsimoes.com/)

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "minimal-web-clipper",
3+
"version": "0.0.1",
4+
"description": "A minimal web clipper",
5+
"scripts": {
6+
"clean": "rm -rf build/*",
7+
"build": "node utils/build.js",
8+
"copy": "cp ./src/img/icon* build",
9+
"dist": "yarn run copy && yarn run build",
10+
"start": "node utils/webserver.js"
11+
},
12+
"devDependencies": {
13+
"clean-webpack-plugin": "^0.1.17",
14+
"copy-webpack-plugin": "^4.2.0",
15+
"css-loader": "^0.25.0",
16+
"file-loader": "^0.11.2",
17+
"fs-extra": "^0.30.0",
18+
"html-loader": "^0.4.5",
19+
"html-webpack-plugin": "2.24.1",
20+
"style-loader": "^0.13.0",
21+
"uglifyjs-webpack-plugin": "^1.1.6",
22+
"url-loader": "^0.6.2",
23+
"webpack": "2.2.1",
24+
"webpack-dev-server": "^2.3.0",
25+
"write-file-webpack-plugin": "3.4.2"
26+
},
27+
"dependencies": {
28+
"debug": "^3.1.0",
29+
"image-to-data-uri": "^1.1.0",
30+
"ios-overlay": "^0.0.3",
31+
"keycode": "^2.1.9",
32+
"lodash.debounce": "^4.0.8",
33+
"promise-timeout-plus": "^0.1.1",
34+
"resolve-url": "^0.2.1",
35+
"selector-query": "^1.0.1",
36+
"spin.js": "^3.1.0",
37+
"styletron": "^3.0.2",
38+
"zepto": "^1.2.0"
39+
}
40+
}

src/background.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title></title>
6+
</head>
7+
<body>
8+
</body>
9+
</html>

src/css/options.css

Whitespace-only changes.

src/css/popup.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.mwc-popup-body {
2+
min-width: 200px;
3+
}
4+
5+
.mwc-header-primary {
6+
background: rgb(144, 67, 153);
7+
border-radius: 4px;
8+
text-align: center;
9+
text-transform: uppercase;
10+
color: white;
11+
font-weight: bold;
12+
padding: 10px;
13+
border-bottom: 2px solid rgba(88, 42, 94);
14+
}
15+
16+
.mwc-control-row {
17+
text-align: center;
18+
padding: 10px;
19+
}
20+
21+
.mwc-control-primary {
22+
display: block;
23+
border-radius: 20px;
24+
line-height: 30px;
25+
height: 30px;
26+
font-size: 12px;
27+
cursor: pointer;
28+
border: 2px solid rgb(144, 67, 153);
29+
padding: 0 15px;
30+
}
31+
32+
.mwc-footer-row {
33+
font-size: 12px;
34+
color: gray;
35+
text-align: left;
36+
padding: 10px;
37+
}
38+
39+
.mwc-footer-num {
40+
font-size: 20px;
41+
color: rgb(144, 67, 153);
42+
font-weight: bold;
43+
}

src/img/icon-128.png

5.26 KB
Loading

src/img/icon-34.png

995 Bytes
Loading

src/img/icon.gvdesign

3.23 KB
Binary file not shown.

0 commit comments

Comments
 (0)