zhangwei 3 年之前
父节点
当前提交
f71f0481ab

+ 6 - 0
README.md

@@ -22,3 +22,9 @@ yarn lint
 
 ### Customize configuration
 See [Configuration Reference](https://cli.vuejs.org/config/).
+
+### watch
+npm run build-watch
+
+### source
+https://www.npmjs.com/package/vue-cli-plugin-chrome-extension-cli

+ 6 - 3
package.json

@@ -5,7 +5,8 @@
   "scripts": {
     "serve": "vue-cli-service serve",
     "build": "vue-cli-service build",
-    "lint": "vue-cli-service lint"
+    "lint": "vue-cli-service lint",
+    "build-watch": "vue-cli-service  --env.NODE_ENV=development build-watch --mode development"
   },
   "dependencies": {
     "core-js": "^3.8.3",
@@ -18,12 +19,14 @@
     "@vue/cli-plugin-eslint": "~5.0.0",
     "@vue/cli-service": "~5.0.0",
     "eslint": "^7.32.0",
-    "eslint-plugin-vue": "^8.0.3"
+    "eslint-plugin-vue": "^8.0.3",
+    "vue-cli-plugin-chrome-extension-cli": "~1.1.2"
   },
   "eslintConfig": {
     "root": true,
     "env": {
-      "node": true
+      "node": true,
+      "webextensions": true
     },
     "extends": [
       "plugin:vue/vue3-essential",

二进制
public/favicon.ico


+ 0 - 17
public/index.html

@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html lang="">
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <meta name="viewport" content="width=device-width,initial-scale=1.0">
-    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
-    <title><%= htmlWebpackPlugin.options.title %></title>
-  </head>
-  <body>
-    <noscript>
-      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
-    </noscript>
-    <div id="app"></div>
-    <!-- built files will be auto injected -->
-  </body>
-</html>

+ 0 - 26
src/App.vue

@@ -1,26 +0,0 @@
-<template>
-  <img alt="Vue logo" src="./assets/logo.png">
-  <HelloWorld msg="Welcome to Your Vue.js App"/>
-</template>
-
-<script>
-import HelloWorld from './components/HelloWorld.vue'
-
-export default {
-  name: 'App',
-  components: {
-    HelloWorld
-  }
-}
-</script>
-
-<style>
-#app {
-  font-family: Avenir, Helvetica, Arial, sans-serif;
-  -webkit-font-smoothing: antialiased;
-  -moz-osx-font-smoothing: grayscale;
-  text-align: center;
-  color: #2c3e50;
-  margin-top: 60px;
-}
-</style>

+ 0 - 58
src/components/HelloWorld.vue

@@ -1,58 +0,0 @@
-<template>
-  <div class="hello">
-    <h1>{{ msg }}</h1>
-    <p>
-      For a guide and recipes on how to configure / customize this project,<br>
-      check out the
-      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
-    </p>
-    <h3>Installed CLI Plugins</h3>
-    <ul>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
-      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
-    </ul>
-    <h3>Essential Links</h3>
-    <ul>
-      <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
-      <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
-      <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
-      <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
-      <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
-    </ul>
-    <h3>Ecosystem</h3>
-    <ul>
-      <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
-      <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
-      <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
-      <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
-      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
-    </ul>
-  </div>
-</template>
-
-<script>
-export default {
-  name: 'HelloWorld',
-  props: {
-    msg: String
-  }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped>
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
-</style>

+ 1 - 0
src/entry/background.js

@@ -0,0 +1 @@
+console.log('hello world background todo something~')

+ 1 - 0
src/entry/content.js

@@ -0,0 +1 @@
+console.log('123 world content todo something~')

+ 4 - 0
src/entry/options.js

@@ -0,0 +1,4 @@
+import { createApp } from 'vue'
+import App from '../view/options.vue'
+
+createApp(App).mount('#app')

+ 1 - 1
src/main.js → src/entry/popup.js

@@ -1,4 +1,4 @@
 import { createApp } from 'vue'
-import App from './App.vue'
+import App from '../view/popup.vue'
 
 createApp(App).mount('#app')

+ 23 - 0
src/manifest.development.json

@@ -0,0 +1,23 @@
+{
+    "manifest_version": 3,
+    "name": "DeNet",
+    "description": "chrome extension",
+    "version": "0.0.1",
+    "background": {
+        "service_worker": "/js/background.js"
+    },
+    "action": {
+        "default_popup": "popup.html"
+    },
+    "content_scripts": [
+        {
+            "matches": [
+                "<all_urls>"
+            ],
+            "js": [
+                "/js/content.js"
+            ]
+        }
+    ],
+    "options_page": "options.html"
+}

+ 26 - 0
src/manifest.production.json

@@ -0,0 +1,26 @@
+{
+    "manifest_version": 3,
+    "name": "DeNet",
+    "description": "chrome extension",
+    "version": "0.0.1",
+    "background": {
+        "service_worker": "/js/background.js"
+    },
+    "action": {
+        "default_popup": "popup.html"
+    },
+    "content_scripts": [
+        {
+            "matches": [
+                "<all_urls>"
+            ],
+            "js": [
+                "/js/content.js"
+            ],
+            "css": [
+                "/js/content.css"
+            ]
+        }
+    ],
+    "options_page": "options.html"
+}

+ 28 - 0
src/view/options.vue

@@ -0,0 +1,28 @@
+<template>
+  <div class="main_app">
+    <h1>Hello {{msg}}</h1>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'optionsView',
+  data () {
+    return {
+      msg: 'options'
+    }
+  }
+}
+
+</script>
+
+<style>
+.main_app {
+  font-family: 'Avenir', Helvetica, Arial, sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+  text-align: center;
+  color: #2c3e50;
+  margin-top: 60px;
+}
+</style>

+ 28 - 0
src/view/popup.vue

@@ -0,0 +1,28 @@
+<template>
+  <div class="main_app">
+    <h1>Hello {{msg}}</h1>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'popupView',
+  data () {
+    return {
+      msg: '123'
+    }
+  }
+}
+
+</script>
+
+<style>
+.main_app {
+  font-family: 'Avenir', Helvetica, Arial, sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+  text-align: center;
+  color: #2c3e50;
+  margin-top: 60px;
+}
+</style>

+ 50 - 3
vue.config.js

@@ -1,4 +1,51 @@
-const { defineConfig } = require('@vue/cli-service')
-module.exports = defineConfig({
-  transpileDependencies: true
+const path = require('path')
+const fs = require('fs')
+
+// Generate pages object
+const pages = {}
+
+function getEntryFile (entryPath) {
+  let files = fs.readdirSync(entryPath)
+  return files
+}
+
+const chromeName = getEntryFile(path.resolve(`src/entry`))
+
+function getFileExtension (filename) {
+  return /[.]/.exec(filename) ? /[^.]+$/.exec(filename)[0] : undefined
+}
+chromeName.forEach((name) => {
+  const fileExtension = getFileExtension(name)
+  const fileName = name.replace('.' + fileExtension, '')
+  pages[fileName] = {
+    entry: `src/entry/${name}`,
+    template: 'public/index.html',
+    filename: `${fileName}.html`
+  }
 })
+
+const isDevMode = process.env.NODE_ENV === 'development'
+
+module.exports = {
+  pages,
+  filenameHashing: false,
+  chainWebpack: (config) => {
+    config.plugin('copy').use(require('copy-webpack-plugin'), [
+      {
+        patterns: [
+          {
+            from: path.resolve(`src/manifest.${process.env.NODE_ENV}.json`),
+            to: `${path.resolve('dist')}/manifest.json`
+          }
+        ]
+      }
+    ])
+  },
+  configureWebpack: {
+    output: {
+      filename: `js/[name].js`,
+      chunkFilename: `[name].js`
+    },
+    devtool: isDevMode ? 'inline-source-map' : false
+  }
+}

+ 5 - 0
yarn.lock

@@ -5838,6 +5838,11 @@ vary@~1.1.2:
   resolved "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
   integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==
 
+vue-cli-plugin-chrome-extension-cli@~1.1.2:
+  version "1.1.2"
+  resolved "https://registry.npmmirror.com/vue-cli-plugin-chrome-extension-cli/-/vue-cli-plugin-chrome-extension-cli-1.1.2.tgz#3ac05bd3661de73d36807a393f0f306eff3f5687"
+  integrity sha512-V6ZN4W3v9tsitsYSO+ukmiKNp0ozyaMJCAAq0kOXBHrtv1R3WQwTQ5WG3gjJDi09trRPiQYnYZRL5YGOhST7rw==
+
 vue-eslint-parser@^8.0.1:
   version "8.3.0"
   resolved "https://registry.npmmirror.com/vue-eslint-parser/-/vue-eslint-parser-8.3.0.tgz#5d31129a1b3dd89c0069ca0a1c88f970c360bd0d"