Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client/vite): first setup

Elian Doran016d59fae161
diff --git a/apps/client/vite.config.ts b/apps/client/vite.config.ts
index 7dedf276bb..f1bc580694 100644
--- a/apps/client/vite.config.ts
+++ b/apps/client/vite.config.ts
@@ -1,21 +1,39 @@
-
+/// <reference types='vitest' />
+import { join } from 'path';
import { defineConfig } from 'vite';
export default defineConfig(() => ({
root: __dirname,
cacheDir: '../../node_modules/.vite/apps/client',
+ server: {
+ port: 4200,
+ host: 'localhost',
+ },
+ preview: {
+ port: 4300,
+ host: 'localhost',
+ },
plugins: [],
- test: {
- watch: false,
- globals: true,
- setupFiles: ["./src/test/setup.ts"],
- environment: "happy-dom",
- include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
- reporters: ["default"],
- coverage: {
- reportsDirectory: './test-output/vitest/coverage',
- provider: 'v8' as const,
- reporter: [ "text", "html" ]
+ // Uncomment this if you are using workers.
+ // worker: {
+ // plugins: [ nxViteTsPaths() ],
+ // },
+ build: {
+ outDir: './dist',
+ emptyOutDir: true,
+ reportCompressedSize: true,
+ 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"),
+ }
}
},
+ commonjsOptions: {
+ transformMixedEsModules: true,
+ }
}));
diff --git a/apps/client/webpack.config.cjs b/apps/client/webpack.config.cjs
deleted file mode 100644
index 15a7307ba9..0000000000
--- a/apps/client/webpack.config.cjs
+++ /dev/null
@@ -1,116 +0,0 @@
-
-const { composePlugins, withNx, withWeb } = require('@nx/webpack');
-const { join } = require('path');
-const CopyPlugin = require('copy-webpack-plugin');
-
-module.exports = composePlugins(
- withNx({
- tsConfig: join(__dirname, './tsconfig.app.json'),
- compiler: "tsc",
- main: join(__dirname, "./src/index.ts"),
- additionalEntryPoints: [
- {
- entryName: "desktop",
- entryPath: join(__dirname, "./src/desktop.ts")
- },
- {
- entryName: "mobile",
- entryPath: join(__dirname, "./src/mobile.ts")
- },
- {
- entryName: "login",
- entryPath: join(__dirname, "./src/login.ts")
- },
- {
- entryName: "setup",
- entryPath: join(__dirname, "./src/setup.ts")
- },
- {
- entryName: "share",
- entryPath: join(__dirname, "./src/share.ts")
- },
- {
- // TriliumNextTODO: integrate set_password into setup entry point/view
- entryName: "set_password",
- entryPath: join(__dirname, "./src/set_password.ts")
- }
- ],
- externalDependencies: [
- "electron"
- ],
- baseHref: '/',
- outputHashing: false,
- optimization: process.env['NODE_ENV'] === 'production'
- }),
- withWeb({
- styles: [],
- stylePreprocessorOptions: {
- sassOptions: {
- quietDeps: true
- }
- },
- }),
- (config) => {
- config.output = {
- path: join(__dirname, 'dist')
- };
-
- config.devServer = {
- port: 4200,
- client: {
- overlay: {
- errors: true,
- warnings: false,
- runtimeErrors: true
- }
- }
- }
-
- config.resolve.fallback = {
- path: false,
- fs: false,
- util: false
- };
-
- const assets = [ "assets", "stylesheets", "libraries", "fonts", "translations" ]
- config.plugins.push(new CopyPlugin({
- patterns: assets.map((asset) => ({
- from: join(__dirname, "src", asset),
- to: asset
- }))
- }));
-
- inlineSvg(config);
- externalJson(config);
-
- return config;
- }
-);
-
-function inlineSvg(config) {
- if (!config.module?.rules) {
- return;
- }
-
- // Alter Nx's asset rule to avoid inlining SVG if they have ?raw prepended.
- const existingRule = config.module.rules.find((r) => r.test.toString() === /\.svg$/.toString());
- existingRule.resourceQuery = { not: [/raw/] };
-
- // Add a rule for prepending ?raw SVGs.
- config.module.rules.push({
- resourceQuery: /raw/,
- type: 'asset/source',
- });
-}
-
-function externalJson(config) {
- if (!config.module?.rules) {
- return;
- }
-
- // Add a rule for prepending ?external.
- config.module.rules.push({
- resourceQuery: /external/,
- type: 'asset/resource',
- });
-}
\ No newline at end of file
diff --git a/package.json b/package.json
index 0bf8c848c6..871e7998bb 100644
--- a/package.json
+++ b/package.json
@@ -55,6 +55,7 @@
"eslint": "^9.8.0",
"eslint-config-prettier": "^10.0.0",
"eslint-plugin-playwright": "^2.0.0",
+ "happy-dom": "~9.20.3",
"jiti": "2.4.2",
"jsdom": "~26.1.0",
"jsonc-eslint-parser": "^2.1.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index afc2a604b4..1fee784b9f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -116,6 +116,9 @@ importers:
eslint-plugin-playwright:
specifier: ^2.0.0
+ happy-dom:
+ specifier: ~9.20.3
+ version: 9.20.3
jiti:
specifier: 2.4.2
version: 2.4.2
@@ -157,7 +160,7 @@ importers:
vitest:
specifier: ^3.0.0
webpack-cli:
specifier: ^6.0.0
version: 6.0.1([email protected])
@@ -308,7 +311,7 @@ importers:
version: 19.1.5(@types/[email protected])
copy-webpack-plugin:
specifier: 13.0.0
happy-dom:
specifier: 17.4.7
version: 17.4.7
@@ -394,7 +397,7 @@ importers:
version: 1.0.2
copy-webpack-plugin:
specifier: 13.0.0
electron:
specifier: 36.2.1
version: 36.2.1
@@ -447,7 +450,7 @@ importers:
version: 11.0.4
copy-webpack-plugin:
specifier: 13.0.0
electron:
specifier: 36.2.1
version: 36.2.1
@@ -619,7 +622,7 @@ importers:
version: 1.4.7
copy-webpack-plugin:
specifier: 13.0.0
csrf-csrf:
specifier: 3.2.2
version: 3.2.2
@@ -790,7 +793,7 @@ importers:
version: 1.0.1
webpack:
specifier: 5.99.8
ws:
specifier: 8.18.2
@@ -842,7 +845,7 @@ importers:
version: 4.1.0
'@ckeditor/ckeditor5-package-tools':
specifier: ^3.0.1
'@typescript-eslint/eslint-plugin':
specifier: ~8.32.0
@@ -902,7 +905,7 @@ importers:
version: 4.1.0
'@ckeditor/ckeditor5-package-tools':
specifier: ^3.0.1
'@typescript-eslint/eslint-plugin':
specifier: ~8.32.0
@@ -962,7 +965,7 @@ importers:
version: 4.1.0
'@ckeditor/ckeditor5-package-tools':
specifier: ^3.0.1
'@typescript-eslint/eslint-plugin':
specifier: ~8.32.0
@@ -1023,13 +1026,13 @@ importers:
'@ckeditor/ckeditor5-dev-utils':
specifier: 43.0.1
'@ckeditor/ckeditor5-inspector':
specifier: '>=4.1.0'
version: 4.1.0
'@ckeditor/ckeditor5-package-tools':
specifier: ^3.0.1
'@typescript-eslint/eslint-plugin':
specifier: ~8.32.0
@@ -1096,7 +1099,7 @@ importers:
version: 4.1.0
'@ckeditor/ckeditor5-package-tools':
specifier: ^3.0.1
'@typescript-eslint/eslint-plugin':
specifier: ~8.32.0
@@ -7066,6 +7069,9 @@ packages:
resolution: {integrity: sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==}
engines: {node: '>= 6'}
+ resolution: {integrity: sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg==}
+
resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==}
engines: {node: '>=4'}
@@ -8744,6 +8750,9 @@ packages:
resolution: {integrity: sha512-NZypxadhCiV5NT4A+Y86aQVVKQ05KDmueja3sz008uJfDRwz028wd0aTiJPwo4RQlvlz0fznkEEBBCHVNWc08g==}
engines: {node: '>=18.0.0'}
+ resolution: {integrity: sha512-eBsgauT435fXFvQDNcmm5QbGtYzxEzOaX35Ia+h6yP/wwa4xSWZh1CfP+mGby8Hk6Xu59mTkpyf72rUXHNxY7A==}
+
resolution: {integrity: sha512-HIp/n38R9kQjDEziXyDTuW3vvoxxyxjxFzXLrBr18uB47GnSt+G9D29fqrpM5ZkspMcPICud3XsBJQ4Y2URg8g==}
@@ -15410,11 +15419,11 @@ snapshots:
transitivePeerDependencies:
- supports-color
dependencies:
'@babel/parser': 7.27.0
'@babel/traverse': 7.27.0
chalk: 5.4.1
fs-extra: 11.3.0
glob: 10.4.5
@@ -15432,58 +15441,58 @@ snapshots:
- uglify-js
- webpack
dependencies:
'@ckeditor/ckeditor5-dev-translations': 43.0.1
chalk: 3.0.0
cli-cursor: 3.1.0
cli-spinners: 2.9.2
cssnano: 6.1.2([email protected])
del: 5.1.0
fs-extra: 11.3.0
is-interactive: 1.0.0
javascript-stringify: 1.6.0
mocha: 7.2.0
postcss: 8.5.3
postcss-import: 14.1.0([email protected])
postcss-mixins: 9.0.4([email protected])
postcss-nesting: 13.0.1([email protected])
shelljs: 0.8.5
through2: 3.0.2
transitivePeerDependencies:
- bluebird
- supports-color
- webpack
dependencies:
chalk: 5.4.1
cli-cursor: 5.0.0
cli-spinners: 3.2.0
cssnano: 7.0.6([email protected])
fs-extra: 11.3.0
is-interactive: 2.0.0
mocha: 10.8.2
postcss: 8.5.3
postcss-import: 16.1.0([email protected])
postcss-mixins: 11.0.3([email protected])
postcss-nesting: 13.0.1([email protected])
shelljs: 0.8.5
through2: 4.0.2
transitivePeerDependencies:
- '@rspack/core'
@@ -15764,29 +15773,29 @@ snapshots:
'@ckeditor/ckeditor5-utils': 45.1.0
ckeditor5: 45.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)
dependencies:
buffer: 6.0.3
chalk: 5.4.1
fs-extra: 11.3.0
glob: 7.2.3
minimist: 1.2.8
postcss: 8.5.3
process: 0.11.10
stylelint: 16.19.1([email protected])
stylelint-config-ckeditor5: 2.0.1([email protected]([email protected]))
typescript: 5.0.4
transitivePeerDependencies:
- '@rspack/core'
- '@swc/core'
@@ -16403,7 +16412,7 @@ snapshots:
make-fetch-happen: 10.2.1
nopt: 6.0.0
proc-log: 2.0.1
- semver: 7.7.1
+ semver: 7.7.2
tar: 6.2.1
which: 2.0.2
transitivePeerDependencies:
@@ -17916,7 +17925,7 @@ snapshots:
'@npmcli/[email protected]':
dependencies:
'@gar/promisify': 1.1.3
- semver: 7.7.1
+ semver: 7.7.2
'@npmcli/[email protected]':
dependencies:
@@ -18190,7 +18199,7 @@ snapshots:
semver: 7.7.1
tsconfig-paths: 4.2.0
transitivePeerDependencies:
- '@babel/traverse'
- '@swc-node/register'
@@ -20224,7 +20233,7 @@ snapshots:
std-env: 3.9.0
test-exclude: 7.0.1
tinyrainbow: 2.0.0
optionalDependencies:
transitivePeerDependencies:
@@ -21784,14 +21793,14 @@ snapshots:
serialize-javascript: 6.0.2
dependencies:
glob-parent: 6.0.2
normalize-path: 3.0.0
schema-utils: 4.3.2
serialize-javascript: 6.0.2
tinyglobby: 0.2.13
dependencies:
@@ -21904,7 +21913,7 @@ snapshots:
dependencies:
icss-utils: 5.1.0([email protected])
loader-utils: 2.0.4
@@ -21916,7 +21925,7 @@ snapshots:
postcss-value-parser: 4.2.0
schema-utils: 3.3.0
semver: 7.7.1
dependencies:
@@ -21931,7 +21940,7 @@ snapshots:
optionalDependencies:
dependencies:
icss-utils: 5.1.0([email protected])
postcss: 8.5.3
@@ -21942,7 +21951,7 @@ snapshots:
postcss-value-parser: 4.2.0
semver: 7.7.2
optionalDependencies:
dependencies:
@@ -21998,6 +22007,8 @@ snapshots:
+
@@ -22984,20 +22995,20 @@ snapshots:
dependencies:
esbuild: 0.17.19
get-tsconfig: 4.10.0
loader-utils: 2.0.4
webpack-sources: 1.4.3
dependencies:
esbuild: 0.25.3
get-tsconfig: 4.10.0
loader-utils: 2.0.4
webpack-sources: 1.4.3
@@ -24169,6 +24180,15 @@ snapshots:
webidl-conversions: 7.0.0
whatwg-mimetype: 3.0.0
+ dependencies:
+ css.escape: 1.5.1
+ entities: 4.5.0
+ iconv-lite: 0.6.3
+ webidl-conversions: 7.0.0
+ whatwg-encoding: 2.0.0
+ whatwg-mimetype: 3.0.0
+
@@ -26021,10 +26041,10 @@ snapshots:
schema-utils: 4.3.2
dependencies:
schema-utils: 4.3.2
@@ -27127,7 +27147,7 @@ snapshots:
camelcase-css: 2.0.1
postcss: 8.5.3
dependencies:
cosmiconfig: 7.1.0
klona: 2.0.6
@@ -27135,7 +27155,7 @@ snapshots:
postcss: 8.5.3
schema-utils: 3.3.0
semver: 7.7.1
dependencies:
@@ -27145,14 +27165,14 @@ snapshots:
semver: 7.7.1
dependencies:
cosmiconfig: 9.0.0([email protected])
jiti: 1.21.7
postcss: 8.5.3
semver: 7.7.2
optionalDependencies:
transitivePeerDependencies:
- typescript
@@ -27733,11 +27753,11 @@ snapshots:
dependencies:
loader-utils: 2.0.4
schema-utils: 3.3.0
dependencies:
@@ -28953,19 +28973,19 @@ snapshots:
'@tokenizer/token': 0.3.0
peek-readable: 5.4.2
dependencies:
loader-utils: 2.0.4
schema-utils: 3.3.0
dependencies:
dependencies:
@@ -29326,7 +29346,7 @@ snapshots:
rimraf: 2.6.3
optional: true
dependencies:
cacache: 15.3.0
find-cache-dir: 3.3.2
@@ -29336,7 +29356,7 @@ snapshots:
serialize-javascript: 5.0.1
source-map: 0.6.1
terser: 5.39.0
webpack-sources: 1.4.3
transitivePeerDependencies:
- bluebird
@@ -29353,14 +29373,14 @@ snapshots:
'@swc/core': 1.11.24(@swc/[email protected])
esbuild: 0.25.4
dependencies:
'@jridgewell/trace-mapping': 0.3.25
jest-worker: 27.5.1
schema-utils: 4.3.2
serialize-javascript: 6.0.2
terser: 5.39.0
optionalDependencies:
'@swc/core': 1.11.24(@swc/[email protected])
esbuild: 0.25.4
@@ -29518,7 +29538,7 @@ snapshots:
dependencies:
chalk: 4.1.2
enhanced-resolve: 5.18.1
@@ -29526,7 +29546,7 @@ snapshots:
semver: 7.7.1
source-map: 0.7.4
typescript: 5.0.4
dependencies:
@@ -30075,6 +30095,50 @@ snapshots:
- tsx
- yaml
+ dependencies:
+ '@vitest/expect': 3.1.3
+ '@vitest/pretty-format': 3.1.3
+ '@vitest/runner': 3.1.3
+ '@vitest/snapshot': 3.1.3
+ '@vitest/spy': 3.1.3
+ '@vitest/utils': 3.1.3
+ chai: 5.2.0
+ debug: 4.4.1([email protected])
+ expect-type: 1.2.1
+ magic-string: 0.30.17
+ pathe: 2.0.3
+ std-env: 3.9.0
+ tinybench: 2.9.0
+ tinyexec: 0.3.2
+ tinyglobby: 0.2.13
+ tinypool: 1.0.2
+ tinyrainbow: 2.0.0
+ why-is-node-running: 2.3.0
+ optionalDependencies:
+ '@types/debug': 4.1.12
+ '@types/node': 22.15.18
+ '@vitest/ui': 3.1.3([email protected])
+ happy-dom: 9.20.3
+ transitivePeerDependencies:
+ - jiti
+ - less
+ - lightningcss
+ - msw
+ - sass
+ - sass-embedded
+ - stylus
+ - sugarss
+ - supports-color
+ - terser
+ - tsx
+ - yaml
+
@@ -30230,7 +30294,7 @@ snapshots:
optionalDependencies:
dependencies:
colorette: 2.0.20
memfs: 4.17.0
@@ -30239,9 +30303,9 @@ snapshots:
range-parser: 1.2.1
schema-utils: 4.3.2
optionalDependencies:
dependencies:
'@types/bonjour': 3.5.13
'@types/connect-history-api-fallback': 1.5.4
@@ -30269,10 +30333,10 @@ snapshots:
serve-index: 1.9.1
sockjs: 0.3.24
spdy: 4.0.2
+ webpack-dev-middleware: 7.4.2([email protected])
optionalDependencies:
webpack-cli: 6.0.1([email protected])
transitivePeerDependencies:
- bufferutil
@@ -30280,7 +30344,7 @@ snapshots:
- supports-color
- utf-8-validate
dependencies:
'@types/bonjour': 3.5.13
'@types/connect-history-api-fallback': 1.5.4
@@ -30308,10 +30372,10 @@ snapshots:
serve-index: 1.9.1
sockjs: 0.3.24
spdy: 4.0.2
- webpack-dev-middleware: 7.4.2([email protected])
optionalDependencies:
webpack-cli: 6.0.1([email protected])
transitivePeerDependencies:
- bufferutil
@@ -30376,7 +30440,7 @@ snapshots:
- esbuild
- uglify-js
dependencies:
'@types/eslint-scope': 3.7.7
'@types/estree': 1.0.7
@@ -30399,7 +30463,7 @@ snapshots:
neo-async: 2.6.2
schema-utils: 4.3.2
tapable: 2.2.1
watchpack: 2.4.2
webpack-sources: 3.2.3
optionalDependencies: