1 Star 7 Fork 0

zengGking / create-vue-chrome-ext

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

create-vue-chrome-ext

打造chrome插件的快速开发项目
————向优秀致敬,向榜样学习

📌介绍

​ 基于Vue3快速开发chrome插件,基于webpack打包工具构建项目。项目采用vue框架对popup页面、options选项页面进行开发。

📄项目结构

create-vue-chrome-ext
├─ dist            # 打包目录
├─ public          # 静态资源文件(该文件夹不会被打包)
│  ├─ img				# 存放插件图标,亦可存放图片资源
│  └─ index.html        # html模板	
├─ src
│  ├─ util              # 工具包	    
│  ├─ background        # chrome插件的background页面	    
│  ├─ content           # chrome插件的content_script
│  ├─ pages              
│  │  ├─ popup            # popup页面
│  │  │  ├─ main.js		    # popup入口文件	
│  │  │  └─ App.vue	 	    # popup主组件
│  │  └─ options          # options选项页面,可以不需要,按照项目需求进行删减。
│  │     ├─ main.js		    # options选项页入口文件
│  │     └─ App.vue	      	# options主组件 
│  └─ manifest.json		  # chrome插件文件清单,必须有这个文件
├─ .browserslistrc 		  # 浏览器兼容配置
├─ .gitignore             # 忽略 git 提交
├─ webpack.config.js      # webpack配置文件
├─ LICENSE                # 开源协议文件
├─ package-lock.json      # 依赖包包版本锁
├─ package.json           # 依赖包管理
└─ README.md              # README 介绍

开始

# clone the project from gitee
git clone https://gitee.com/zengGking/create-vue-chrome-ext
# clone the project from github
git clone https://github.com/zengGking/create-vue-chrome-ext

# enter the project directory
cd create-vue-chrome-ext

# install dependency
npm install

# develop
npm run dev

# production
npm run build

# loading the dist folder with chrome 

📃使用说明

  • 支持sass,如想更改预编译语言,可自行安装配置。
  • 支持i18n。
  • content_script支持jQuery。
  • 基于Vue3,可自行引入elementUI、vant等组件库。
  • 可更换插件图标,在public/img目录下替换掉原来的图标即可。
  • ⚠在正式发布上线前,建议将webpack.config.js的devtool功能关闭。
  • ⚠如果不需要options选项页,请在webpack.config.js中修改如下配置,提升开发体验。
//webpack.config.js
module.exports = {
    entry: {
        popup: "./src/view/popup/main.js",
        //options: './src/view//options/main.js', 删除
    },
    //...
    plugins:[
       //...
       //	删除以下内容
      //  new HtmlWebpackPlugin({
      //       title: 'Options_html',
      //       filename: 'html/options.html',
      //       template: path.resolve(__dirname, 'public/index.html'),
      //       chunks: ['options']
      //   }),
    ]
}

📧Message消息通信

// background.js
import { Message } from "../utils/Message";
const message = new Message();
message.listening('hellow', (data) => {
    console.log('contentjs传来的数据1:', data);
})
message.listening('hellow', (data)=>{
    console.log('contentjs传来的数据2:', data);
})
message.listeningResponse('sum', (data) => {
    //需要返回响应数据
    console.log('sum1');
    return data.data.reduce((pre, cur) => pre + cur, 0)
})

// content.js
import { Message } from "../utils/Message";
const message = new Message()
message.send('hellow', { msg: 'hellow1' })
message.request('sum', { data: [1111, 2222, 3333, 4444, 5555, 6666] }).then((res) => {
  console.log('求和结果:', res);
})

💡content_script进行http请求

原理:由content_script转发http请求给background,由background发送http请求并返回数据给content_script。

// background.js
import { HttpServer } from "./HttpServer";
const httpServer = new HttpServer();//开启http服务,content_script才能进行http请求
httpServer.start()

//content.js
import { HttpClient } from "./HttpClient";
const httpClient = new HttpClient()
httpClient.request("https://wenku.baidu.com/gsearch/rec/homerec?pn=1&rn=16", { method: 'get', params: { limit: 10 } })
    .then((res) => {
      console.log('http测试', res);
  	})

⚠注意!!!

如果打包时出现 Module not found 错误,请进行以下尝试:

// 打开\node_modules\axios\package.json添加以下配置
{
  ...
  "exports": {
    ...
    "./lib/*":"./lib/*"
  },
}
//打开\node_modules\@vespaiach\axios-fetch-adapter\index.js修改为以下内容
import axios from 'axios';
import settle from 'axios/lib/core/settle';
import buildURL from 'axios/lib/helpers/buildURL';
import buildFullPath from 'axios/lib/core/buildFullPath';
import utils from 'axios/lib/utils';
import browser from 'axios/lib/platform/browser'
const { isUndefined, isFormData } = utils;
const { isStandardBrowserEnv } = browser

📖更新日志

  • 2024/01/10更新 v0.2.2

    • 优化了消息通信
    • 优化了http请求
  • 2023/04/22更新 v0.2.1

    • 新增i18n
    • 优化项目构建
  • 2023/04/03更新 v0.1.1

    • 封装了Message消息通信和Storage存储,更方便开发
    • 使content_script可以进行http请求
    • 优化目录结构与webpack配置
  • 2023/03/29更新 v0.0.2

    • 优化配置,提高了开发效率,提升了开发体验
    • 优化目录结构,使符合开发习惯
    • package与manifest文件统一version信息

项目交流

​ 如果对项目有疑问,欢迎在Issues留下你的问题。

计划下次更新

  • 支持ts
MIT License Copyright (c) 2023 zengGking Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于Vue3快速开发chrome插件,基于webpack打包工具构建项目。项目采用vue框架对popup页面、options选项页面进行开发。 展开 收起
JavaScript 等 4 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zengGking/create-vue-chrome-ext.git
git@gitee.com:zengGking/create-vue-chrome-ext.git
zengGking
create-vue-chrome-ext
create-vue-chrome-ext
master

搜索帮助