Using vue-cli, set up a project that allows for two distinct web apps to exist in the same repository together: a "main" site and an "admin" site.
Each site would have a distinct top-level Vue app (entry point) and a distinct "public/" folder of assets to copy into each site. Each site would have some Vue components specific to itself, but also be able to share components common to both sites.
All searches done using DuckDuckGo
man vue-cli-service
(attempting to find the manual page for the
vue-cli-service command, to check for CLI options)
./node_modules/.bin/vue-cli-service --help
and see the man page that
way. Didn't find any CLI options that would configure the public folder
path in the man page.vue-cli public folder path
Search vue-cli html-webpack-plugin settings
vue.config.js
and customize
options to the html-webpack-plugin (under "Modifying Options of a Plugin"):// vue.config.js
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
args[0].template = '/Users/username/proj/app/templates/index.html'
return args
})
}
}
Seeing mention of publicPath in places, searched vue publicPath config
<script src="/custom-public/app.js">
Searched vue-cli multiple public folders
// vue.config.js
const path = require('path')
const publicDir = 'assets/html';
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.tap(args => {
args[0].template = path.resolve(publicDir + '/index.html');
return args
})
config
.plugin('copy')
.tap(([pathConfigs]) => {
pathConfigs[0].from = path.resolve(publicDir);
return [pathConfigs]
})
}
}
npm run build-admin
to build an "admin site" or npm run build-main
to build a "main" site, each
using its own public folder.Searches: vue.config.js runtime options
, vue-cli multiple vue.config.js
and vue.config.js config variables
before landing on
Environment Variables and Modes | Vue CLI 3
--mode
option of
vue-cli-service
to specify the .env file to load, and the variables are
available inside your vue.config.js at the process.env
variable.vue.config.js:
let PUBLIC_PATH = process.env.VUE_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]
})
}
}
package.json npm run scripts:
"scripts": {
"serve": "vue-cli-service serve",
"build-admin": "vue-cli-service build --mode admin --dest admin-dist ./src/admin/index.js",
"build": "vue-cli-service build --mode main --dest dist ./src/main/index.js",
"lint": "vue-cli-service lint"
},
.env config files:
# .env.admin
VUE_SITE_NAME=admin
# .env.main
VUE_SITE_NAME=main
So:
npm build
would output the site to the default dist/ folder, use
./src/main/index.js as the entry point (instead of default src/main.js from
a default vue-cli project) and use the default public/ folder.npm build-admin
would output the site to admin-dist/ (so as not to overwrite
the dist/ for the main site), use ./src/admin/index.js as entry point and use
the folder "custom-public/" instead of default public/ to get its index.html and
static assets.0.4879s
.