Skip to content

Commit f72ea70

Browse files
committed
Initial commit of a vue-cli plugin
1 parent 84959a9 commit f72ea70

File tree

10 files changed

+2134
-1
lines changed

10 files changed

+2134
-1
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_size = 2

.eslintrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true
5+
},
6+
'extends': [
7+
'plugin:vue/essential',
8+
'@vue/standard'
9+
],
10+
rules: {
11+
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
12+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
13+
},
14+
}

README.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,71 @@
11
# vue-cli-plugin-browser-extension
2-
Browser extension development plugin for vue-cli 3.0
2+
Browser extension development plugin for vue-cli 3.x
3+
4+
## What does it do?
5+
This is intended to be a [email protected] replacement for [https://github.com/Kocal/vue-web-extension](https://github.com/Kocal/vue-web-extension).
6+
This plugin adds a new command `ext-serve` to your vue applications.
7+
This new command is only for running a livereload server while testing out your browser extension.
8+
This removes the entrypoint of `main.js`, and as such will not scaffold a general vue app.
9+
That behavior might change when support for a standalone tab application exists, but for now it is gone.
10+
Packaging and deploying will still be done with `yarn build` and zipping in up for chrome, firefox, or whichever other browser you wish to develop for.
11+
It makes some assumptions about your project setup.
12+
I hope to be able to scaffold an app so that itentifying the below in unnecessary.
13+
14+
```
15+
|- src/
16+
|- assets/
17+
|- Static assets in use in your app, like logo.png
18+
|- icons/
19+
|- Icons for your extension. Should include a 16, 19, 38, 48, 128 px square image
20+
|- popup/
21+
|- router/
22+
|- pages/
23+
|- Index.vue
24+
|- index.js
25+
|- routes.js
26+
|- App.vue
27+
|- popup.html
28+
|- popup.js
29+
|- store/
30+
|- actions.js
31+
|- getters.js
32+
|- index.js
33+
|- mutation-types.js
34+
|- mutations.js
35+
|- background.js
36+
|- manifest.json
37+
```
38+
39+
## Usage
40+
Running the Livereload server.
41+
This will build and write to the local `dist` directory.
42+
You can then add this as an unpacked plugin to your browser, and will continue to update as you make changes.
43+
**NOTE:** you cannot get HMR support in the popup window, however, closing and reopening will refresh your content.
44+
45+
```sh
46+
yarn ext-serve
47+
```
48+
49+
50+
## Testing
51+
This library is following the standard styling of vue projects, and those are really the only tests to perform.
52+
53+
```sh
54+
yarn test
55+
```
56+
57+
## Roadmap
58+
- Add generators for background.js, popup, vuex, and vue-router stuff. (Make startup a breeze)
59+
- Add some generator options for other pieces of browser extensions. This includes scaffolding the components/dirs, and registering the build options into the build time hooks.
60+
- Dev Tools
61+
- Dedicated extension pages
62+
- Options Pages
63+
- Content scripts
64+
- Add zipping to the bundle for production builds
65+
- More configurability in scaffolding, like Kocal/vue-web-extension does
66+
- A preset
67+
68+
## Credits
69+
- [https://github.com/Kocal/vue-web-extension](https://github.com/Kocal/vue-web-extension) For inspiration on app and build structure
70+
- [https://github.com/YuraDev/vue-chrome-extension-template](https://github.com/YuraDev/vue-chrome-extension-template) For the logo crop and app/scaffold structure
71+
- [@YuraDev](https://github.com/YuraDev) for the wonderful WCER plugin for livereloading extensions

generator.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = (api, { config }) => {
2+
const pkg = {
3+
scripts: {
4+
'ext-serve': 'vue-cli-service ext-serve'
5+
},
6+
devDependencies: {
7+
'vue-cli-plugin-build-watch': '^1.0.0'
8+
}
9+
}
10+
11+
api.extendPackage(pkg)
12+
}

index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { log } = require('@vue/cli-shared-utils')
2+
const CopyWebpackPlugin = require('copy-webpack-plugin')
3+
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader')
4+
const { version } = require('./package.json')
5+
6+
module.exports = (api) => {
7+
api.configureWebpack(webpackConfig => {
8+
delete webpackConfig.entry.app
9+
webpackConfig.entry.background = './src/background.js'
10+
webpackConfig.entry['popup/popup'] = './src/popup/popup.js'
11+
12+
webpackConfig.plugins.push(new CopyWebpackPlugin([
13+
{ from: './src/icons', to: 'icons', ignore: ['icon.xcf'] },
14+
{ from: './src/popup/popup.html', to: 'popup/popup.html' },
15+
{
16+
from: './src/manifest.json',
17+
to: 'manifest.json',
18+
transform: (content) => {
19+
const jsonContent = JSON.parse(content)
20+
jsonContent.version = version
21+
22+
if (process.env.NODE_ENV === 'development') {
23+
jsonContent['content_security_policy'] = "script-src 'self' 'unsafe-eval'; object-src 'self'"
24+
}
25+
26+
return JSON.stringify(jsonContent, null, 2)
27+
}
28+
}
29+
]))
30+
31+
if (process.env.HMR === 'true') {
32+
webpackConfig.plugins = (webpackConfig.plugins || []).concat([
33+
new ChromeExtensionReloader()
34+
])
35+
}
36+
})
37+
38+
api.registerCommand('ext-serve', (...args) => {
39+
log('Starting webpack in watch mode...')
40+
41+
api.configureWebpack((webpackConfig) => {
42+
webpackConfig.watch = true
43+
})
44+
45+
api.service.run('build', ...args)
46+
})
47+
}

locales/en.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"com": {
3+
"rewardstyle": {
4+
"browserExt": {
5+
"tasks": {
6+
"extServe": {
7+
"description": "Builds and watches the project, writing the files to the output directory"
8+
}
9+
}
10+
}
11+
}
12+
}
13+
}

logo.png

565 KB
Loading

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "vue-cli-plugin-browser-extension",
3+
"version": "0.0.1",
4+
"description": "Browser extension development plugin for vue-cli 3.0",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "eslint ."
8+
},
9+
"keywords": [
10+
"chrome",
11+
"extension",
12+
"browser",
13+
"plugin",
14+
"vue",
15+
"cli",
16+
"3"
17+
],
18+
"license": "GPL-3.0",
19+
"repository": "[email protected]:adambullmer/vue-cli-plugin-browser-extension.git",
20+
"author": "Adam Bullmer <[email protected]>",
21+
"devDependencies": {
22+
"@vue/eslint-config-standard": "^3.0.0-rc.3",
23+
"eslint": "^5.1.0",
24+
"eslint-plugin-vue": "^4.5.0"
25+
},
26+
"dependencies": {
27+
"@vue/cli-shared-utils": "^3.0.0-rc.3",
28+
"copy-webpack-plugin": "^4.5.2",
29+
"webpack-chrome-extension-reloader": "^0.8.3"
30+
}
31+
}

ui.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = (api) => {
2+
api.describeTask({
3+
match: /vue-cli-service ext-serve/,
4+
description: 'com.rewardstyle.browserExt.tasks.extServe.description',
5+
link: 'https://github.com/rewardstyle/linkninjax-ext'
6+
})
7+
}

0 commit comments

Comments
 (0)