forked from trent_larson/crowd-funder-for-time-pwa
refactor: reorganize Vite config into modular files
Split monolithic vite.config.mjs into separate config files: - vite.config.web.mts - vite.config.electron.mts - vite.config.capacitor.mts - vite.config.pywebview.mts - vite.config.common.mts - vite.config.utils.mts Updates: - Modify package.json scripts to use specific config files - Add electron-builder as dev dependency - Update electron build configuration - Fix electron resource paths - Remove old vite.config.mjs and utils.js This change improves maintainability by: - Separating concerns for different build targets - Making build configurations more explicit - Reducing complexity in individual config files
This commit is contained in:
55
vite.config.common.mts
Normal file
55
vite.config.common.mts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import dotenv from "dotenv";
|
||||
import { loadAppConfig } from "./vite.config.utils.mts";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config();
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
export async function createBuildConfig(mode: string) {
|
||||
const appConfig = await loadAppConfig();
|
||||
const isElectron = mode === "electron";
|
||||
const isCapacitor = mode === "capacitor";
|
||||
const isPyWebView = mode === "pywebview";
|
||||
|
||||
if (isElectron || isPyWebView) {
|
||||
process.env.VITE_PWA_ENABLED = 'false';
|
||||
}
|
||||
|
||||
return {
|
||||
base: isElectron || isPyWebView ? "./" : "/",
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
port: parseInt(process.env.VITE_PORT || "8080"),
|
||||
fs: { strict: false },
|
||||
},
|
||||
build: {
|
||||
outDir: isElectron ? "dist-electron" : "dist",
|
||||
assetsDir: 'assets',
|
||||
chunkSizeWarningLimit: 1000
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
||||
'process.env.VITE_PWA_ENABLED': JSON.stringify(!(isElectron || isPyWebView)),
|
||||
__dirname: isElectron ? JSON.stringify(process.cwd()) : '""',
|
||||
},
|
||||
resolve: {
|
||||
alias: appConfig.aliasConfig
|
||||
},
|
||||
optimizeDeps: {
|
||||
exclude: isElectron ? [
|
||||
'register-service-worker',
|
||||
'workbox-window',
|
||||
'web-push',
|
||||
'serviceworker-webpack-plugin'
|
||||
] : []
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig(async () => createBuildConfig('web'));
|
||||
Reference in New Issue
Block a user