Skip to content

Commit eb169b9

Browse files
authored
Merge pull request #9 from sanyu1225/develop
version 1.0.8
2 parents a95a0a2 + 1d12c91 commit eb169b9

File tree

9 files changed

+74
-63
lines changed

9 files changed

+74
-63
lines changed

README-zh_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ vue add chrome-extension-cli
5757
### 本地开发 跟 生产模式
5858

5959
- 使用` npm run build-watch`运行开发模式,将生成一个`dist`文件。 安装[Extension Reloader](https://chrome.google.com/webstore/detail/extensions-reloader/fimgfedafeadlieiabdeeaodndnlbhid),以便在热更新。 (注意,当您更改 manifest.json 文件时,它不会自动加载,您需要点选 extension 页面中的更新)
60-
60+
- ### manifest版本 3 不支援使用 `npm run build-watch` 因为 manifest版本 3不支援 [CSP](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy)
6161
- 生产模式 `npm run build`,并将其压缩成 zip 并部署到 chrome 商店中。
6262

6363
### prompts.js

README-zh_TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ vue add chrome-extension-cli
5757
### 本地開發 跟 生產模式
5858

5959
- 使用` npm run build-watch`運行開發模式,將生成一個`dist`文件。 安裝[Extension Reloader](https://chrome.google.com/webstore/detail/extensions-reloader/fimgfedafeadlieiabdeeaodndnlbhid),以便在熱更新。 (注意,當您更改 manifest.json 文件時,它不會自動加載,您需要點選 extension 頁面中的更新)
60-
60+
- ### manifest版本 3 不支援使用 `npm run build-watch` 因為 manifest版本 3不支援 [CSP](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy)
6161
- 生產模式 `npm run build`,並將其壓縮成 zip 並部署到 chrome 商店中。
6262

6363
### prompts.js

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ vue add chrome-extension-cli
5757
### Run Development mode and Production
5858

5959
- Run development mode with `npm run build-watch` and a `dist` file will be generated. Install [Extension Reloader](https://chrome.google.com/webstore/detail/extensions-reloader/fimgfedafeadlieiabdeeaodndnlbhid) to reload chrome extensions easily everytime you reload. (take note that when u change manifest.json file, it will not automatically load, you need to click update extension )
60+
- ### manifest_version 3 can't use `npm run build-watch` beacause version 3 can't support [CSP](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy)
6061
- Build for production `npm run build` and zip it and deploy onto chrome store.
61-
6262
### prompts.js
6363

6464
Vue CLI prompt is based on [inquirer.js](https://github.com/SBoudrias/Inquirer.js) api.

generator/generate/generateEnv.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

generator/generate/manifest.js

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,58 @@ const generateManifest = (options, manifestPath) => {
77
description,
88
version
99
}
10-
11-
if (components.includes('background')) {
12-
manifestJson.background = {
13-
'scripts': ['/js/background.js'],
14-
'persistent': false
15-
}
10+
const mf2_Key = {
11+
'background': 'background',
12+
'popup': 'browser_action',
13+
'content': 'content_scripts',
14+
'options': 'options_page',
15+
'devtools': 'devtools_page'
1616
}
17-
if (components.includes('popup')) {
18-
manifestJson.browser_action = { default_popup: 'popup.html' }
17+
const mf3_Key = {
18+
'background': 'background',
19+
'popup': 'action',
20+
'content': 'action',
21+
'options': 'options_page',
22+
'devtools': 'devtools_page'
1923
}
20-
if (components.includes('content')) {
21-
manifestJson.content_scripts = [{
24+
const mf3_content = {
25+
'background': {
26+
'service_worker': '/js/background.js'
27+
},
28+
'action': {
29+
'default_popup': 'popup.html'
30+
},
31+
'content_scripts': [{
2232
'matches': ['<all_urls>'],
2333
'js': ['/js/content.js']
24-
}]
34+
}],
35+
'options_page': 'options.html',
36+
'devtools_page': 'devtools.html'
2537
}
26-
if (components.includes('options')) {
27-
manifestJson.options_page = 'options.html'
38+
const mf2_content = {
39+
'background': {
40+
'scripts': ['/js/background.js'],
41+
'persistent': false
42+
},
43+
'browser_action': { default_popup: 'popup.html' },
44+
'content_scripts': [{
45+
'matches': ['<all_urls>'],
46+
'js': ['/js/content.js']
47+
}],
48+
'options_page': 'options.html',
49+
'devtools_page': 'devtools.html'
2850
}
29-
if (components.includes('devtools')) {
30-
manifestJson.devtools_page = 'devtools.html'
51+
if (manifest_version === 3) {
52+
components.forEach(element => {
53+
manifestJson[mf3_Key[element]] = mf3_content[mf3_Key[element]]
54+
})
55+
} else {
56+
components.forEach(element => {
57+
manifestJson[mf2_Key[element]] = mf2_content[mf2_Key[element]]
58+
})
59+
// Development build of manifest.json
60+
manifestJson['content_security_policy'] =
61+
"script-src 'self' 'unsafe-eval'; object-src 'self'"
3162
}
3263

3364
// Production build of manifest.json
@@ -38,9 +69,7 @@ const generateManifest = (options, manifestPath) => {
3869
encoding: 'utf-8'
3970
}
4071
)
41-
// Development build of manifest.json
42-
manifestJson['content_security_policy'] =
43-
"script-src 'self' 'unsafe-eval'; object-src 'self'"
72+
4473
fs.writeFileSync(
4574
`${manifestPath}/manifest.development.json`,
4675
JSON.stringify(manifestJson, null, 4),

generator/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const generateIndex = require('./generate/generateIndex')
33
const deleteFile = require('./generate/deleteFile')
44
const editTsConfig = require('./generate/editTsConfig')
55
const editPackage = require('./generate/editPackage')
6-
const generateEnv = require('./generate/generateEnv')
76
const fs = require('fs')
87

98
module.exports = async (api, options, { vueVersion }) => {
@@ -31,7 +30,6 @@ module.exports = async (api, options, { vueVersion }) => {
3130

3231
api.onCreateComplete(() => {
3332
generateManifest(options, api.resolve('./src')) // add manifest.json
34-
generateEnv(api.resolve('./'), components) // add env file
3533
// edit tsconfig.json
3634
if (isTypeScript) editTsConfig(api.resolve('./tsconfig.json'))
3735
// delete vue Initial file
@@ -40,9 +38,6 @@ module.exports = async (api, options, { vueVersion }) => {
4038

4139
// Modify file content
4240
api.afterInvoke(() => {
43-
if (isTypeScript) {
44-
replaceFileString('./vue.config.js', /\{name\}\.js/, '{name}.js', '{name}.ts')
45-
}
4641
components.forEach((e) => {
4742
const whiteList = ['popup', 'options', 'devtools']
4843
if (whiteList.includes(e)) {

generator/template/vue.config.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
const CopyWebpackPlugin = require('copy-webpack-plugin')
22
const path = require('path')
3+
const fs = require('fs')
34

45
// Generate pages object
56
const pages = {}
67

7-
const chromeName = process.env.VUE_APP_FILE.split(',')
8+
function getEntryFile (entryPath) {
9+
let files = fs.readdirSync(entryPath)
10+
return files
11+
}
12+
13+
const chromeName = getEntryFile(path.resolve(`src/entry`))
814

15+
function getFileExtension (filename) {
16+
return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename)[0] : undefined
17+
}
918
chromeName.forEach((name) => {
10-
pages[name] = {
11-
entry: `src/entry/${name}.js`,
19+
const fileExtension = getFileExtension(name)
20+
const fileName = name.replace('.' + fileExtension, '')
21+
pages[fileName] = {
22+
entry: `src/entry/${name}`,
1223
template: 'public/index.html',
13-
filename: `${name}.html`
24+
filename: `${fileName}.html`
1425
}
1526
})
1627

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
module.exports = (api, opts) => {
22
api.chainWebpack(webpackConfig => {
33
// remove split chunks for chrome extension, make sure everything in a file
4-
webpackConfig.optimization.delete("splitChunks");
5-
});
4+
webpackConfig.optimization.delete('splitChunks')
5+
})
66

7-
api.configureWebpack(webpackConfig => { });
8-
9-
api.registerCommand("build-watch", (...args) => {
7+
api.registerCommand('build-watch', (...args) => {
108
api.configureWebpack(webpackConfig => {
11-
webpackConfig.watch = true;
12-
});
13-
api.service.run("build", ...args);
14-
});
15-
};
9+
webpackConfig.watch = true
10+
})
11+
api.service.run('build', ...args)
12+
})
13+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-plugin-chrome-extension-cli",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Use Vue CLI generate chrome extension template | generate chrome extension with vue.js",
55
"author": "sanyu1225 <[email protected]>",
66
"scripts": {},

0 commit comments

Comments
 (0)