generated from cawa-93/vite-electron-builder
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8433f98
commit f2540e2
Showing
1 changed file
with
25 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |