2025-05-16 20:48:29 +03:00
|
|
|
/// <reference types='vitest' />
|
2026-01-11 00:55:42 +02:00
|
|
|
import prefresh from '@prefresh/vite';
|
2026-01-05 11:07:40 +02:00
|
|
|
import { join } from 'path';
|
|
|
|
|
import webpackStatsPlugin from 'rollup-plugin-webpack-stats';
|
|
|
|
|
import { defineConfig } from 'vite';
|
|
|
|
|
import { viteStaticCopy } from 'vite-plugin-static-copy'
|
2025-05-16 21:31:57 +03:00
|
|
|
|
2025-06-15 11:56:50 +03:00
|
|
|
const assets = [ "assets", "stylesheets", "fonts", "translations" ];
|
2025-04-22 22:06:10 +03:00
|
|
|
|
2025-09-01 11:53:17 +03:00
|
|
|
const isDev = process.env.NODE_ENV === "development";
|
2026-01-10 23:27:14 +02:00
|
|
|
let plugins: any = [];
|
2025-09-01 11:53:17 +03:00
|
|
|
|
2026-01-11 00:55:42 +02:00
|
|
|
if (isDev) {
|
|
|
|
|
// Add Prefresh for Preact HMR in development
|
|
|
|
|
plugins = [
|
|
|
|
|
prefresh()
|
|
|
|
|
];
|
|
|
|
|
} else {
|
2025-09-01 11:53:17 +03:00
|
|
|
plugins = [
|
2025-05-16 21:31:57 +03:00
|
|
|
viteStaticCopy({
|
|
|
|
|
targets: assets.map((asset) => ({
|
2026-03-31 20:31:34 +00:00
|
|
|
src: `src/${asset}/**/*`,
|
|
|
|
|
dest: asset,
|
|
|
|
|
rename: { stripBase: 2 }
|
2025-05-16 21:31:57 +03:00
|
|
|
}))
|
2025-05-17 19:52:04 +03:00
|
|
|
}),
|
|
|
|
|
viteStaticCopy({
|
|
|
|
|
targets: [
|
|
|
|
|
{
|
2026-03-31 20:31:34 +00:00
|
|
|
src: "../../node_modules/@excalidraw/excalidraw/dist/prod/fonts/**/*",
|
2025-05-17 19:52:04 +03:00
|
|
|
dest: "",
|
|
|
|
|
}
|
|
|
|
|
]
|
2025-06-07 13:02:37 +03:00
|
|
|
}),
|
|
|
|
|
webpackStatsPlugin()
|
2025-09-01 11:53:17 +03:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default defineConfig(() => ({
|
2026-01-28 22:23:00 +02:00
|
|
|
root: __dirname,
|
|
|
|
|
cacheDir: '../../.cache/vite',
|
2025-09-01 11:53:17 +03:00
|
|
|
base: "",
|
|
|
|
|
plugins,
|
2026-01-10 23:27:14 +02:00
|
|
|
// Use esbuild for JSX transformation (much faster than Babel)
|
|
|
|
|
esbuild: {
|
|
|
|
|
jsx: 'automatic',
|
|
|
|
|
jsxImportSource: 'preact',
|
|
|
|
|
jsxDev: isDev
|
|
|
|
|
},
|
2026-01-10 23:03:43 +02:00
|
|
|
css: {
|
|
|
|
|
transformer: 'lightningcss',
|
2026-01-11 00:31:48 +02:00
|
|
|
devSourcemap: isDev
|
2026-01-10 23:03:43 +02:00
|
|
|
},
|
2025-05-20 18:06:55 +03:00
|
|
|
resolve: {
|
|
|
|
|
alias: [
|
2025-06-10 22:22:47 +03:00
|
|
|
{
|
|
|
|
|
find: "react",
|
|
|
|
|
replacement: "preact/compat"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
find: "react-dom",
|
|
|
|
|
replacement: "preact/compat"
|
2025-05-20 18:06:55 +03:00
|
|
|
}
|
2025-06-10 21:23:46 +03:00
|
|
|
],
|
|
|
|
|
dedupe: [
|
|
|
|
|
"react",
|
2025-06-10 22:22:47 +03:00
|
|
|
"react-dom",
|
|
|
|
|
"preact",
|
|
|
|
|
"preact/compat",
|
|
|
|
|
"preact/hooks"
|
2025-05-20 18:06:55 +03:00
|
|
|
]
|
|
|
|
|
},
|
2026-01-10 22:12:41 +02:00
|
|
|
optimizeDeps: {
|
|
|
|
|
include: [
|
|
|
|
|
"ckeditor5-premium-features",
|
|
|
|
|
"ckeditor5",
|
2026-01-11 10:55:13 +02:00
|
|
|
"mathlive"
|
2026-01-10 22:12:41 +02:00
|
|
|
]
|
|
|
|
|
},
|
2025-05-16 20:48:29 +03:00
|
|
|
build: {
|
2025-05-16 21:06:30 +03:00
|
|
|
target: "esnext",
|
2026-01-28 22:23:00 +02:00
|
|
|
outDir: './dist',
|
2025-05-16 20:48:29 +03:00
|
|
|
emptyOutDir: true,
|
|
|
|
|
reportCompressedSize: true,
|
2025-06-11 22:03:25 +03:00
|
|
|
sourcemap: false,
|
2025-05-16 20:48:29 +03:00
|
|
|
rollupOptions: {
|
|
|
|
|
input: {
|
2026-01-28 22:23:00 +02:00
|
|
|
index: join(__dirname, "index.html"),
|
|
|
|
|
login: join(__dirname, "src", "login.ts"),
|
2025-05-16 20:48:29 +03:00
|
|
|
setup: join(__dirname, "src", "setup.ts"),
|
|
|
|
|
set_password: join(__dirname, "src", "set_password.ts"),
|
2026-01-10 19:51:03 +02:00
|
|
|
runtime: join(__dirname, "src", "runtime.ts"),
|
2025-10-20 12:39:38 +03:00
|
|
|
print: join(__dirname, "src", "print.tsx")
|
2025-05-16 21:11:03 +03:00
|
|
|
},
|
|
|
|
|
output: {
|
2026-01-20 16:33:46 +02:00
|
|
|
entryFileNames: (chunk) => {
|
|
|
|
|
// We enforce a hash in the main index file to avoid caching issues, this only works because we have the HTML entry point.
|
2026-02-10 16:30:16 +02:00
|
|
|
if (chunk.name === "index" || chunk.name === "print") {
|
2026-01-20 16:33:46 +02:00
|
|
|
return "src/[name]-[hash].js";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For EJS-rendered pages (e.g. login) we need to have a stable name.
|
|
|
|
|
return "src/[name].js";
|
|
|
|
|
},
|
2026-01-10 20:43:43 +02:00
|
|
|
chunkFileNames: "src/[name]-[hash].js",
|
2026-03-14 12:15:43 +02:00
|
|
|
assetFileNames: "src/[name]-[hash].[ext]"
|
2025-05-17 23:53:58 +03:00
|
|
|
},
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
},
|
2025-06-19 19:38:10 +03:00
|
|
|
test: {
|
2025-06-19 21:30:10 +03:00
|
|
|
environment: "happy-dom",
|
|
|
|
|
setupFiles: [
|
|
|
|
|
"./src/test/setup.ts"
|
2026-03-05 22:07:11 +02:00
|
|
|
],
|
|
|
|
|
reporters: [
|
|
|
|
|
"verbose",
|
|
|
|
|
["html", { outputFile: "./test-output/vitest/html/index.html" }]
|
|
|
|
|
],
|
2025-06-19 19:38:10 +03:00
|
|
|
},
|
2025-05-16 20:48:29 +03:00
|
|
|
commonjsOptions: {
|
|
|
|
|
transformMixedEsModules: true,
|
2025-06-10 22:22:47 +03:00
|
|
|
},
|
|
|
|
|
define: {
|
|
|
|
|
"process.env.IS_PREACT": JSON.stringify("true"),
|
2025-05-16 20:48:29 +03:00
|
|
|
}
|
2025-04-22 22:06:10 +03:00
|
|
|
}));
|