The app build command 'npm run build:app' can now be configured to put outputs into
a specified directory. Previously, this location was hardcoded at 'dist/app' (and
for the library build config it is still hardcoded at 'dist/lib'. This was done due
to the need to run different builds for different variants ('default' and 'starter')
and to have the outputs in different locations, i.e. not to have the first build be
overwritten by the second. The default output directory remains 'dist/app'.
As an example:
- 'npm run build:app' will output to 'dist/app'
- VITE_OUT_DIR='dist/tmp run build:app' will output to 'dist/tmp'
- 'VITE_OUT_DIR='dist/app-starter' VITE_SHACLVUE_VARIANT='starter' run build:app' will
build the starter variant and output it to 'dist/app-starter'
Successive builds to different subdirectories of the same parent directory will not
influence each other.
Another small change was to log the app variant during the build process, just for
debugging purposes.
89 lines
2.7 KiB
JavaScript
89 lines
2.7 KiB
JavaScript
// Plugins
|
|
import Components from 'unplugin-vue-components/vite';
|
|
import Vue from '@vitejs/plugin-vue';
|
|
import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify';
|
|
import ViteFonts from 'unplugin-fonts/vite';
|
|
|
|
// Utilities
|
|
import { defineConfig } from 'vite';
|
|
import { fileURLToPath, URL } from 'node:url';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
// Git repo version
|
|
import { execSync } from 'child_process';
|
|
const commitHash = execSync('git rev-parse HEAD').toString().trim();
|
|
const commitHashShort = execSync('git rev-parse --short HEAD')
|
|
.toString()
|
|
.trim();
|
|
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
|
|
|
|
// Output directory of build process
|
|
const outDir = process.env.VITE_OUT_DIR || 'dist/app';
|
|
const variant = process.env.VITE_SHACLVUE_VARIANT || 'default';
|
|
console.log(`Building shacl-vue application variant: '${variant}'`)
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [
|
|
Vue({
|
|
template: { transformAssetUrls },
|
|
}),
|
|
// https://github.com/vuetifyjs/vuetify-loader/tree/master/packages/vite-plugin#readme
|
|
Vuetify(),
|
|
Components(),
|
|
ViteFonts({
|
|
google: {
|
|
families: [
|
|
{
|
|
name: 'Roboto',
|
|
styles: 'wght@100;300;400;500;700;900',
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
{
|
|
name: 'no-spa-fallback-for-html',
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
if (req.url && req.url.endsWith('.html')) {
|
|
const filePath = path.join(process.cwd(), 'public', req.url);
|
|
if (!fs.existsSync(filePath)) {
|
|
res.statusCode = 404;
|
|
res.end('Not Found');
|
|
return; // stop here
|
|
}
|
|
}
|
|
next();
|
|
});
|
|
},
|
|
},
|
|
],
|
|
define: {
|
|
'process.env': {},
|
|
__COMMIT_HASH__: JSON.stringify(commitHash),
|
|
__COMMIT_HASH_SHORT__: JSON.stringify(commitHashShort),
|
|
__BRANCH__: JSON.stringify(branch),
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
extensions: ['.js', '.json', '.jsx', '.mjs', '.ts', '.tsx', '.vue'],
|
|
},
|
|
build: {
|
|
outDir,
|
|
emptyOutDir: true,
|
|
sourcemap: true,
|
|
rollupOptions: {
|
|
input: 'index.html',
|
|
},
|
|
},
|
|
server: {
|
|
port: 3000,
|
|
mimeTypes: {
|
|
'.vue': 'application/javascript',
|
|
},
|
|
},
|
|
base: './',
|
|
});
|