Skip to content
Snippets Groups Projects
Commit ff371c41 authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Base with vue-webextension

parent 8ef8afae
No related branches found
No related tags found
2 merge requests!4Setup CI,!3Setup the stack to use Vue in both the web extension and a regular html form
File moved
<!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>
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view />
</div>
</template>
<style lang="scss">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>
src/assets/logo.png

6.69 KiB

browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
console.log("Hello from the background");
console.log(request, sender, sendResponse);
});
<template>
<div>
<p>{{ defaultText }}</p>
</div>
</template>
<script>
export default {
name: "HelloWorld",
mounted() {
browser.runtime.sendMessage({});
},
computed: {
defaultText() {
return browser.i18n.getMessage("extName");
},
},
};
</script>
<style scoped>
p {
font-size: 20px;
}
</style>
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
Vue.config.productionTip = false;
new Vue({
router,
store,
render: (h) => h(App),
}).$mount("#app");
{
"manifest_version": 2,
"name": "__MSG_extName__",
"homepage_url": "http://localhost:8080/",
"description": "Customizable unicode virtual keyboard on text input.",
"default_locale": "en",
"permissions": [
"<all_urls>",
"*://*/*"
],
"icons": {
"16": "icons/keyboard-16.png",
"48": "icons/keyboard-48.png",
"128": "icons/keyboard-128.png"
},
"background": {
"scripts": [
"js/background.js"
],
"persistent": false
},
"browser_action": {
"default_popup": "popup.html",
"default_title": "Virtual keyboard",
"default_icon": {
"19": "icons/keyboard-19.png",
"38": "icons/keyboard-38.png"
}
},
"options_ui": {
"page": "options.html",
"browser_style": true
}
}
<template>
<hello-world />
</template>
<script>
import HelloWorld from "@/components/HelloWorld.vue";
export default {
name: "App",
components: { HelloWorld },
};
</script>
<style>
html {
width: 400px;
height: 400px;
}
</style>
import Vue from "vue";
import App from "./App.vue";
/* eslint-disable no-new */
new Vue({
el: "#app",
render: (h) => h(App),
});
<template>
<hello-world />
</template>
<script>
import HelloWorld from "@/components/HelloWorld.vue";
export default {
name: "App",
components: { HelloWorld },
};
</script>
<style>
html {
width: 400px;
height: 400px;
}
</style>
import Vue from "vue";
import App from "./App.vue";
/* eslint-disable no-new */
new Vue({
el: "#app",
render: (h) => h(App),
});
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "Home",
component: Home,
},
{
path: "/about",
name: "About",
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ "../views/About.vue"),
},
];
const router = new VueRouter({
routes,
});
export default router;
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {},
mutations: {},
actions: {},
modules: {},
});
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png" />
<HelloWorld msg="Welcome to Your Vue.js App" />
</div>
</template>
<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
export default {
name: "Home",
components: {
HelloWorld,
},
};
</script>
module.exports = {
lintOnSave: false,
pages: {
popup: {
template: "public/browser-extension.html",
entry: "./src/popup/main.js",
title: "Popup",
},
options: {
template: "public/browser-extension.html",
entry: "./src/options/main.js",
title: "Options",
},
},
pluginOptions: {
browserExtension: {
componentOptions: {
background: {
entry: "src/background.js",
},
},
},
},
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment