You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.7 KiB
110 lines
3.7 KiB
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";
|
|
|
|
// Explicitly set platform
|
|
process.env.VITE_PLATFORM = mode;
|
|
|
|
if (isElectron || isPyWebView || isCapacitor) {
|
|
process.env.VITE_PWA_ENABLED = 'false';
|
|
}
|
|
|
|
return defineConfig({
|
|
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: 1500,
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
'nostr-tools': ['nostr-tools'],
|
|
'vue-vendor': ['vue', 'vue-router', 'vue-facing-decorator'],
|
|
'crypto-deps': [
|
|
'crypto-browserify',
|
|
'stream-browserify',
|
|
'buffer',
|
|
'asn1.js'
|
|
]
|
|
}
|
|
},
|
|
external: isElectron ? [
|
|
'electron',
|
|
'electron-store',
|
|
'vm',
|
|
...appConfig.electronExternals || []
|
|
] : ['vm']
|
|
}
|
|
},
|
|
define: {
|
|
__VUE_OPTIONS_API__: true,
|
|
__VUE_PROD_DEVTOOLS__: false,
|
|
'import.meta.env.MODE': JSON.stringify(process.env.NODE_ENV || 'development'),
|
|
'import.meta.env.DEV': process.env.NODE_ENV !== 'production',
|
|
'import.meta.env.PROD': process.env.NODE_ENV === 'production',
|
|
'import.meta.env.SSR': false,
|
|
'import.meta.env.VITE_PLATFORM': JSON.stringify(mode),
|
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
|
'process.env.VITE_PWA_ENABLED': JSON.stringify(!(isElectron || isPyWebView || isCapacitor)),
|
|
__dirname: isElectron ? JSON.stringify(process.cwd()) : '""',
|
|
__USE_QR_READER__: JSON.stringify(!isCapacitor),
|
|
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
|
global: 'globalThis'
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
'@capacitor/app': path.resolve(__dirname, 'node_modules/@capacitor/app'),
|
|
...appConfig.aliasConfig,
|
|
'nostr-tools': path.resolve(__dirname, 'node_modules/nostr-tools/lib/esm'),
|
|
'nostr-tools/nip06': path.resolve(__dirname, 'node_modules/nostr-tools/lib/esm/nip06.js'),
|
|
'dexie-export-import': path.resolve(__dirname, 'node_modules/dexie-export-import'),
|
|
'crypto': path.resolve(__dirname, 'node_modules/crypto-browserify'),
|
|
'stream': path.resolve(__dirname, 'node_modules/stream-browserify'),
|
|
'buffer': path.resolve(__dirname, 'node_modules/buffer/'),
|
|
'asn1.js': path.resolve(__dirname, 'node_modules/asn1.js')
|
|
}
|
|
},
|
|
optimizeDeps: {
|
|
include: [
|
|
'dexie-export-import',
|
|
'crypto-browserify',
|
|
'stream-browserify',
|
|
'buffer',
|
|
'nostr-tools',
|
|
'nostr-tools/nip06',
|
|
'asn1.js/lib/asn1/base/index.js'
|
|
],
|
|
exclude: isElectron ? [
|
|
'register-service-worker',
|
|
'workbox-window',
|
|
'web-push',
|
|
'serviceworker-webpack-plugin',
|
|
'vm'
|
|
] : ['vm']
|
|
}
|
|
});
|
|
}
|
|
|
|
export default defineConfig(async () => createBuildConfig('web'));
|
|
|