2023-12-28 00:25:49 +00:00
|
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
import fs from 'fs';
|
|
|
|
import { resolve } from 'path'
|
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import { ViteEjsPlugin } from "vite-plugin-ejs";
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
import process from 'process'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Before actually building the pages with Vite, we do an intermediate build step using ejs
|
|
|
|
* Importing this separately and joining them using ejs
|
|
|
|
* allows us to split some repeating HTML that cannot be added
|
|
|
|
* by Vue itself (e.g. style/script loading, common meta head tags, Widgetbot)
|
|
|
|
* The vite-plugin-ejs handles this automatically
|
|
|
|
*/
|
|
|
|
let assetsSrcPath = 'src_assets/common/assets/web';
|
|
|
|
let assetsDstPath = 'build/assets/web';
|
|
|
|
|
2024-03-09 15:47:55 +00:00
|
|
|
if (process.env.SUNSHINE_BUILD_HOMEBREW) {
|
|
|
|
console.log("Building for homebrew, using default paths")
|
2023-12-28 00:25:49 +00:00
|
|
|
}
|
2024-03-09 15:47:55 +00:00
|
|
|
else {
|
2024-11-02 16:03:11 +00:00
|
|
|
// If the paths supplied in the environment variables contain any symbolic links
|
|
|
|
// at any point in the series of directories, the entire build will fail with
|
|
|
|
// a cryptic error message like this:
|
|
|
|
// RollupError: The "fileName" or "name" properties of emitted chunks and assets
|
|
|
|
// must be strings that are neither absolute nor relative paths.
|
|
|
|
// To avoid this, we resolve the potential symlinks using `fs.realpathSync` before
|
|
|
|
// doing anything else with the paths.
|
2024-03-09 15:47:55 +00:00
|
|
|
if (process.env.SUNSHINE_SOURCE_ASSETS_DIR) {
|
2024-11-02 16:03:11 +00:00
|
|
|
let path = resolve(fs.realpathSync(process.env.SUNSHINE_SOURCE_ASSETS_DIR), "common/assets/web");
|
|
|
|
console.log("Using srcdir from Cmake: " + path);
|
|
|
|
assetsSrcPath = path;
|
2024-03-09 15:47:55 +00:00
|
|
|
}
|
|
|
|
if (process.env.SUNSHINE_ASSETS_DIR) {
|
2024-11-02 16:03:11 +00:00
|
|
|
let path = resolve(fs.realpathSync(process.env.SUNSHINE_ASSETS_DIR), "assets/web");
|
|
|
|
console.log("Using destdir from Cmake: " + path);
|
|
|
|
assetsDstPath = path;
|
2024-03-09 15:47:55 +00:00
|
|
|
}
|
2023-12-28 00:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let header = fs.readFileSync(resolve(assetsSrcPath, "template_header.html"))
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
vue: 'vue/dist/vue.esm-bundler.js'
|
|
|
|
}
|
|
|
|
},
|
2024-10-19 02:49:34 +00:00
|
|
|
base: './',
|
2023-12-28 00:25:49 +00:00
|
|
|
plugins: [vue(), ViteEjsPlugin({ header })],
|
|
|
|
root: resolve(assetsSrcPath),
|
|
|
|
build: {
|
|
|
|
outDir: resolve(assetsDstPath),
|
|
|
|
rollupOptions: {
|
|
|
|
input: {
|
|
|
|
apps: resolve(assetsSrcPath, 'apps.html'),
|
|
|
|
config: resolve(assetsSrcPath, 'config.html'),
|
|
|
|
index: resolve(assetsSrcPath, 'index.html'),
|
|
|
|
password: resolve(assetsSrcPath, 'password.html'),
|
|
|
|
pin: resolve(assetsSrcPath, 'pin.html'),
|
|
|
|
troubleshooting: resolve(assetsSrcPath, 'troubleshooting.html'),
|
|
|
|
welcome: resolve(assetsSrcPath, 'welcome.html'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|