Skip to content

Commit

Permalink
update packages's vite config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ryannewcomer committed Apr 10, 2024
1 parent 8433f98 commit f2540e2
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions packages/main/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
import {node} from '../../.electron-vendors.cache.json';
import {join} from 'node:path';
import {node} from '../../electron-vendors.config.json';
import {join} from 'path';
import {builtinModules} from 'module';

import {defineConfig} from 'vite';
import {loadAndSetEnv} from '../../scripts/loadAndSetEnv.mjs';

const PACKAGE_ROOT = __dirname;
const PROJECT_ROOT = join(PACKAGE_ROOT, '../..');

/**
* @type {import('vite').UserConfig}
* Vite looks for `.env.[mode]` files only in `PACKAGE_ROOT` directory.
* Therefore, you must manually load and set the environment variables from the root directory above
*/
loadAndSetEnv(process.env.MODE, process.cwd());

/**
* @see https://vitejs.dev/config/
*/
const config = {
mode: process.env.MODE,
export default defineConfig({
root: PACKAGE_ROOT,
envDir: PROJECT_ROOT,
resolve: {
alias: {
'/@/': join(PACKAGE_ROOT, 'src') + '/',
},
},
build: {
ssr: true,
sourcemap: 'inline',
target: `node${node}`,
outDir: 'dist',
assetsDir: '.',
minify: process.env.MODE !== 'development',
minify: process.env.MODE === 'development' ? false : 'terser',
terserOptions: {
ecma: 2020,
compress: {
passes: 2,
},
safari10: false,
},
lib: {
entry: 'src/index.ts',
formats: ['es'],
formats: ['cjs'],
},
rollupOptions: {
external: ['electron', 'electron-devtools-installer', ...builtinModules],
output: {
entryFileNames: '[name].js',
entryFileNames: '[name].cjs',
},
},
emptyOutDir: true,
reportCompressedSize: false,
},
};

export default config;
});

0 comments on commit f2540e2

Please sign in to comment.