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.
153 lines
4.6 KiB
153 lines
4.6 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';
|
|
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
|
|
// 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 {
|
|
base: isElectron || isPyWebView ? "./" : "./",
|
|
plugins: [
|
|
vue(),
|
|
// Add Node.js polyfills for Electron environment
|
|
isElectron ? nodePolyfills({
|
|
include: ['util', 'stream', 'buffer', 'events', 'assert', 'crypto'],
|
|
globals: {
|
|
Buffer: true,
|
|
global: true,
|
|
process: true,
|
|
},
|
|
protocolImports: true,
|
|
}) : null,
|
|
].filter(Boolean),
|
|
server: {
|
|
port: parseInt(process.env.VITE_PORT || "8080"),
|
|
fs: { strict: false },
|
|
},
|
|
build: {
|
|
outDir: isElectron ? "dist-electron" : "dist",
|
|
assetsDir: 'assets',
|
|
chunkSizeWarningLimit: 1000,
|
|
target: isElectron ? 'node18' : 'esnext',
|
|
rollupOptions: {
|
|
external: isCapacitor
|
|
? ['@capacitor/app']
|
|
: isElectron
|
|
? [
|
|
'sqlite3',
|
|
'sqlite',
|
|
'electron',
|
|
'fs',
|
|
'path',
|
|
'crypto',
|
|
'util',
|
|
'stream',
|
|
'buffer',
|
|
'events',
|
|
'assert',
|
|
'constants',
|
|
'os',
|
|
'net',
|
|
'tls',
|
|
'dns',
|
|
'http',
|
|
'https',
|
|
'zlib',
|
|
'url',
|
|
'querystring',
|
|
'punycode',
|
|
'string_decoder',
|
|
'timers',
|
|
'domain',
|
|
'dgram',
|
|
'child_process',
|
|
'cluster',
|
|
'module',
|
|
'vm',
|
|
'readline',
|
|
'repl',
|
|
'tty',
|
|
'v8',
|
|
'worker_threads'
|
|
]
|
|
: [],
|
|
output: {
|
|
format: isElectron ? 'cjs' : 'es',
|
|
generatedCode: {
|
|
preset: 'es2015'
|
|
}
|
|
}
|
|
}
|
|
},
|
|
define: {
|
|
'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()) : '""',
|
|
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
|
__USE_QR_READER__: JSON.stringify(!isCapacitor),
|
|
'process.platform': JSON.stringify('browser'),
|
|
'process.version': JSON.stringify('v16.0.0'),
|
|
'process.env.NODE_DEBUG': JSON.stringify(false),
|
|
'global.process': JSON.stringify({
|
|
platform: 'browser',
|
|
version: 'v16.0.0',
|
|
env: { NODE_DEBUG: false }
|
|
})
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
...appConfig.aliasConfig,
|
|
'path': path.resolve(__dirname, './src/utils/node-modules/path.js'),
|
|
'fs': path.resolve(__dirname, './src/utils/node-modules/fs.js'),
|
|
'crypto': path.resolve(__dirname, './src/utils/node-modules/crypto.js'),
|
|
'nostr-tools/nip06': mode === 'development'
|
|
? 'nostr-tools/nip06'
|
|
: path.resolve(__dirname, 'node_modules/nostr-tools/nip06'),
|
|
'nostr-tools/core': mode === 'development'
|
|
? 'nostr-tools'
|
|
: path.resolve(__dirname, 'node_modules/nostr-tools'),
|
|
'nostr-tools': path.resolve(__dirname, 'node_modules/nostr-tools'),
|
|
'dexie-export-import': path.resolve(__dirname, 'node_modules/dexie-export-import')
|
|
}
|
|
},
|
|
optimizeDeps: {
|
|
include: [
|
|
'nostr-tools',
|
|
'nostr-tools/nip06',
|
|
'nostr-tools/core',
|
|
'dexie-export-import',
|
|
'@jlongster/sql.js'
|
|
],
|
|
exclude: isElectron ? [
|
|
'register-service-worker',
|
|
'workbox-window',
|
|
'web-push',
|
|
'serviceworker-webpack-plugin'
|
|
] : []
|
|
}
|
|
};
|
|
}
|
|
|
|
export default defineConfig(async () => createBuildConfig('web'));
|
|
|