Multi-vue-site example initial commit

This commit is contained in:
Noah 2020-01-28 14:53:49 -08:00
parent 1f9a361f76
commit 5c50414766
15 changed files with 157 additions and 3 deletions

View File

@ -1,4 +1,26 @@
# hello-world
# Vue CLI Multisite Base Example
Just some stuff I hacked together to get a vue-cli created app to support
multiple sites. Key things to look at compared to a base `vue create <app>`
site:
* package.json:
* Customizes the `npm run build` commands to support multiple sites, an "admin"
and a "main" site. Each one has a custom dist/ output folder (--dest option)
and a custom entry point (e.g. "./src/admin/index.js" instead of default
"./src/main.js")
* vue.config.js:
* This file needs to be **added** to a Vue project, as it's not there by default.
It configures the html-webpack-plugin to change the name of the "public" folder
that gets put into the dist/ folder; so each site can have its own public
folder.
* Uses environment variable SITE_NAME to choose the public folder to use.
* custom-public/ is for the admin site and added a "hello.txt" to verify
correct functionality. The main site uses the public/ folder like normal.
So when you run `npm run build-admin` it creates `dist-admin/` taking the
custom-public folder and the admin entrypoint. `npm run build-main` creates the
`dist/` folder and the normal public folder.
## Project setup
```

BIN
custom-public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

17
custom-public/index.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<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>hello-world</title>
</head>
<body>
<noscript>
<strong>We're sorry but hello-world 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>

View File

@ -4,7 +4,8 @@
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build-admin": "SITE_NAME=admin vue-cli-service build --dest admin-dist ./src/admin/index.js",
"build": "SITE_NAME=main vue-cli-service build --dest dist ./src/main/index.js",
"lint": "vue-cli-service lint"
},
"dependencies": {

View File

@ -1,3 +1,4 @@
<!-- CUSTOM PAGE -->
<!DOCTYPE html>
<html lang="en">
<head>
@ -5,7 +6,7 @@
<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>hello-world</title>
<title>CUSTOM hello-world</title>
</head>
<body>
<noscript>

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

28
src/main/App.vue Normal file
View File

@ -0,0 +1,28 @@
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</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>

BIN
src/main/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1,58 @@
<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>

8
src/main/main.js Normal file
View File

@ -0,0 +1,8 @@
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')

19
vue.config.js Normal file
View File

@ -0,0 +1,19 @@
let PUBLIC_PATH = process.env.SITE_NAME === "admin" ? "custom-public" : "public";
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
args[0].template = PUBLIC_PATH + '/index.html'
return args
})
config
.plugin('copy')
.tap(([pathConfigs]) => {
pathConfigs[0].from = PUBLIC_PATH;
return [pathConfigs]
})
}
}