Files
Trilium/apps/client/vite.config.mts

111 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-05-16 20:48:29 +03:00
/// <reference types='vitest' />
import { join, resolve } from 'path';
import { defineConfig, type Plugin } from 'vite';
2025-05-16 21:31:57 +03:00
import { viteStaticCopy } from 'vite-plugin-static-copy'
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
import preact from "@preact/preset-vite";
2025-05-16 21:31:57 +03:00
const assets = [ "assets", "stylesheets", "fonts", "translations" ];
const isDev = process.env.NODE_ENV === "development";
let plugins: any = [
preact({
babel: {
compact: !isDev
}
})
];
if (!isDev) {
plugins = [
...plugins,
2025-05-16 21:31:57 +03:00
viteStaticCopy({
targets: assets.map((asset) => ({
2025-05-26 18:14:47 +03:00
src: `src/${asset}/*`,
2025-05-16 21:31:57 +03:00
dest: asset
}))
2025-05-17 19:52:04 +03:00
}),
viteStaticCopy({
structured: true,
targets: [
{
2025-09-02 13:59:09 +03:00
src: "../../node_modules/@excalidraw/excalidraw/dist/prod/fonts/*",
2025-05-17 19:52:04 +03:00
dest: "",
}
]
}),
webpackStatsPlugin()
]
}
export default defineConfig(() => ({
root: __dirname,
cacheDir: '../../node_modules/.vite/apps/client',
base: "",
plugins,
resolve: {
alias: [
{
find: "react",
replacement: "preact/compat"
},
{
find: "react-dom",
replacement: "preact/compat"
}
],
dedupe: [
"react",
"react-dom",
"preact",
"preact/compat",
"preact/hooks"
]
},
2025-05-16 20:48:29 +03:00
build: {
target: "esnext",
2025-05-16 20:48:29 +03:00
outDir: './dist',
emptyOutDir: true,
reportCompressedSize: true,
2025-06-11 22:03:25 +03:00
sourcemap: false,
2025-05-16 20:48:29 +03:00
rollupOptions: {
input: {
desktop: join(__dirname, "src", "desktop.ts"),
mobile: join(__dirname, "src", "mobile.ts"),
login: join(__dirname, "src", "login.ts"),
setup: join(__dirname, "src", "setup.ts"),
share: join(__dirname, "src", "share.ts"),
set_password: join(__dirname, "src", "set_password.ts"),
runtime: join(__dirname, "src", "runtime.ts"),
print: join(__dirname, "src", "print.tsx")
},
output: {
2025-05-19 20:04:51 +03:00
entryFileNames: "src/[name].js",
chunkFileNames: "src/[name].js",
assetFileNames: "src/[name].[ext]",
manualChunks: {
"ckeditor5": [ "@triliumnext/ckeditor5" ]
},
},
onwarn(warning, rollupWarn) {
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
return;
}
rollupWarn(warning);
2025-05-16 20:48:29 +03:00
}
2025-04-26 23:03:16 +03:00
}
},
test: {
2025-06-19 21:30:10 +03:00
environment: "happy-dom",
setupFiles: [
"./src/test/setup.ts"
]
},
2025-05-16 20:48:29 +03:00
commonjsOptions: {
transformMixedEsModules: true,
},
define: {
"process.env.IS_PREACT": JSON.stringify("true"),
2025-05-16 20:48:29 +03:00
}
}));