| 
									
										
										
										
											2025-05-16 20:48:29 +03:00
										 |  |  | /// <reference types='vitest' />
 | 
					
						
							| 
									
										
										
										
											2025-05-20 18:06:55 +03:00
										 |  |  | import { join, resolve } from 'path'; | 
					
						
							| 
									
										
										
										
											2025-07-05 17:58:36 +03:00
										 |  |  | import { defineConfig, type Plugin } from 'vite'; | 
					
						
							| 
									
										
										
										
											2025-05-16 21:31:57 +03:00
										 |  |  | import { viteStaticCopy } from 'vite-plugin-static-copy' | 
					
						
							| 
									
										
										
										
											2025-06-07 13:02:37 +03:00
										 |  |  | import webpackStatsPlugin from 'rollup-plugin-webpack-stats'; | 
					
						
							| 
									
										
										
										
											2025-08-03 13:28:40 +03:00
										 |  |  | import preact from "@preact/preset-vite"; | 
					
						
							| 
									
										
										
										
											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"; | 
					
						
							|  |  |  | 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: "", | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             ] | 
					
						
							| 
									
										
										
										
											2025-06-07 13:02:37 +03:00
										 |  |  |         }), | 
					
						
							|  |  |  |         webpackStatsPlugin() | 
					
						
							| 
									
										
										
										
											2025-09-01 11:53:17 +03:00
										 |  |  |     ] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default defineConfig(() => ({ | 
					
						
							|  |  |  |     root: __dirname, | 
					
						
							|  |  |  |     cacheDir: '../../node_modules/.vite/apps/client', | 
					
						
							|  |  |  |     base: "", | 
					
						
							|  |  |  |     plugins, | 
					
						
							| 
									
										
										
										
											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
										 |  |  |         ] | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-05-16 20:48:29 +03:00
										 |  |  |     build: { | 
					
						
							| 
									
										
										
										
											2025-05-16 21:06:30 +03:00
										 |  |  |         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"), | 
					
						
							| 
									
										
										
										
											2025-10-18 20:23:17 +03: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: { | 
					
						
							| 
									
										
										
										
											2025-05-19 20:04:51 +03:00
										 |  |  |                 entryFileNames: "src/[name].js", | 
					
						
							|  |  |  |                 chunkFileNames: "src/[name].js", | 
					
						
							| 
									
										
										
										
											2025-06-15 12:41:03 +03:00
										 |  |  |                 assetFileNames: "src/[name].[ext]", | 
					
						
							|  |  |  |                 manualChunks: { | 
					
						
							|  |  |  |                     "ckeditor5": [ "@triliumnext/ckeditor5" ] | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											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
										 |  |  | })); |