From 1d6a1f64c93bd96e7700e7476936ffa81db02df8 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Mon, 26 Aug 2024 16:35:09 +0200 Subject: [PATCH] Fix twenty-front performances (#6744) I have investigated the performance of our frontend vite build: `npx nx run twenty:start` of `npx nx run twenty:build` RAM usage: - 160Mb: vite serve - background typescript checker: 2.5GB - background eslint checker: 3.5GB I'm introducing two environment variables in FE .env to disable these checkers on lower configuration (and to disable them from CD build): ``` # VITE_DISABLE_TYPESCRIPT_CHECKER=true # VITE_DISABLE_ESLINT_CHECKER=true ``` --- nx.json | 2 +- packages/twenty-front/.env.example | 2 ++ packages/twenty-front/package.json | 2 +- packages/twenty-front/vite.config.ts | 18 +++++++++++++----- packages/twenty-server/project.json | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/nx.json b/nx.json index 4ec242fd5172..35b6e7501700 100644 --- a/nx.json +++ b/nx.json @@ -32,7 +32,7 @@ }, "start": { "cache": true, - "dependsOn": ["^typecheck","^build"] + "dependsOn": ["^build"] }, "lint": { "executor": "@nx/eslint:lint", diff --git a/packages/twenty-front/.env.example b/packages/twenty-front/.env.example index 423b00b0733b..3fccb201c4b9 100644 --- a/packages/twenty-front/.env.example +++ b/packages/twenty-front/.env.example @@ -3,3 +3,5 @@ GENERATE_SOURCEMAP=false # ———————— Optional ———————— # CHROMATIC_PROJECT_TOKEN= +# VITE_DISABLE_TYPESCRIPT_CHECKER=true +# VITE_DISABLE_ESLINT_CHECKER=true \ No newline at end of file diff --git a/packages/twenty-front/package.json b/packages/twenty-front/package.json index 0478db13abe5..2fed3289213d 100644 --- a/packages/twenty-front/package.json +++ b/packages/twenty-front/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "build": "npx vite build && sh ./scripts/inject-runtime-env.sh", - "build:sourcemaps": "VITE_BUILD_SOURCEMAP=true NODE_OPTIONS=--max-old-space-size=4096 npx nx build", + "build:sourcemaps": "VITE_BUILD_SOURCEMAP=true VITE_DISABLE_TYPESCRIPT_CHECKER=true VITE_DISABLE_ESLINT_CHECKER=true NODE_OPTIONS=--max-old-space-size=4096 npx nx build", "start:prod": "NODE_ENV=production npx vite --host", "tsup": "npx tsup" }, diff --git a/packages/twenty-front/vite.config.ts b/packages/twenty-front/vite.config.ts index 682b6466ab40..a9059b4d71f1 100644 --- a/packages/twenty-front/vite.config.ts +++ b/packages/twenty-front/vite.config.ts @@ -15,7 +15,12 @@ export default defineConfig(({ command, mode }) => { /* Using explicit env variables, there is no need to expose all of them (security). */ - const { REACT_APP_SERVER_BASE_URL, VITE_BUILD_SOURCEMAP } = env; + const { + REACT_APP_SERVER_BASE_URL, + VITE_BUILD_SOURCEMAP, + VITE_DISABLE_TYPESCRIPT_CHECKER, + VITE_DISABLE_ESLINT_CHECKER, + } = env; const isBuildCommand = command === 'build'; @@ -24,13 +29,16 @@ export default defineConfig(({ command, mode }) => { : path.resolve(__dirname, './tsconfig.dev.json'); const checkers: Checkers = { - typescript: { - tsconfigPath: tsConfigPath, - }, overlay: false, }; - if (!isBuildCommand) { + if (VITE_DISABLE_TYPESCRIPT_CHECKER !== 'true') { + checkers['typescript'] = { + tsconfigPath: tsConfigPath, + }; + } + + if (VITE_DISABLE_ESLINT_CHECKER !== 'true') { checkers['eslint'] = { lintCommand: 'eslint . --report-unused-disable-directives --max-warnings 0 --config .eslintrc.cjs', diff --git a/packages/twenty-server/project.json b/packages/twenty-server/project.json index 2a993b848ecd..a92e19caae28 100644 --- a/packages/twenty-server/project.json +++ b/packages/twenty-server/project.json @@ -22,7 +22,7 @@ }, "start": { "executor": "nx:run-commands", - "dependsOn": ["build"], + "dependsOn": ["typecheck", "build"], "options": { "cwd": "packages/twenty-server", "command": "NODE_ENV=development && nest start --watch"