From 551d9e762b01d9c4b109b94225e356dc123b0aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Thu, 9 Nov 2023 19:50:53 +0100 Subject: [PATCH] fix(demo): improve vite optimizeDeps config --- demo/package-lock.json | 226 +++++++++++++++++++++++++++++++++++++++++ demo/package.json | 1 + demo/vite.config.ts | 43 +++----- 3 files changed, 241 insertions(+), 29 deletions(-) diff --git a/demo/package-lock.json b/demo/package-lock.json index a9b8fb90..0a36275c 100644 --- a/demo/package-lock.json +++ b/demo/package-lock.json @@ -158,6 +158,7 @@ "@types/express": "^4.17.17", "@types/wicg-file-system-access": "^2020.9.6", "@types/ws": "^8.5.5", + "fast-glob": "^3.3.2", "ts-node": "^10.9.1", "typescript": "~5.2.2", "vite": "~4.4.9" @@ -2277,6 +2278,41 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -2578,6 +2614,18 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", @@ -2881,6 +2929,43 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/fast-glob": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fastq": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", + "integrity": "sha512-wBrocU2LCXXa+lWBt8RoIRD89Fi8OdABODa/kEnyeyjS5aZO5/GNvI5sEINADqP/h8M29UHTHUb53sUu5Ihqdw==", + "dev": true, + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/finalhandler": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", @@ -2965,6 +3050,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -3056,6 +3153,36 @@ "node": ">= 0.10" } }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -3075,6 +3202,15 @@ "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", @@ -3083,6 +3219,19 @@ "node": ">= 0.6" } }, + "node_modules/micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "dependencies": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, "node_modules/mime": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", @@ -3206,6 +3355,18 @@ "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", "dev": true }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/postcss": { "version": "8.4.30", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.30.tgz", @@ -3269,6 +3430,26 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -3304,6 +3485,16 @@ "node": ">= 6" } }, + "node_modules/reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true, + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, "node_modules/rollup": { "version": "3.29.3", "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.3.tgz", @@ -3320,6 +3511,29 @@ "fsevents": "~2.3.2" } }, + "node_modules/run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -3490,6 +3704,18 @@ "node": ">=6" } }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", diff --git a/demo/package.json b/demo/package.json index 35e2b5e7..a17fffc4 100644 --- a/demo/package.json +++ b/demo/package.json @@ -20,6 +20,7 @@ "@types/express": "^4.17.17", "@types/wicg-file-system-access": "^2020.9.6", "@types/ws": "^8.5.5", + "fast-glob": "^3.3.2", "ts-node": "^10.9.1", "typescript": "~5.2.2", "vite": "~4.4.9" diff --git a/demo/vite.config.ts b/demo/vite.config.ts index 60b4536a..842f49ad 100644 --- a/demo/vite.config.ts +++ b/demo/vite.config.ts @@ -1,7 +1,9 @@ import { defineConfig } from 'vite' +import glob from 'fast-glob' import * as fs from 'fs' import url from 'url' import path from 'path' +import pkg from './package.json' assert { type: 'json' } const cdnDomain = 'http://127.0.0.2:5173' @@ -46,37 +48,20 @@ export default defineConfig({ } ], optimizeDeps: { - // This is require because vscode is a local dependency - // and vite doesn't want to optimize it and the number of modules makes chrome hang + // This is require because vite excludes local dependencies from being optimized + // Monaco-vscode-api packages are local dependencies and the number of modules makes chrome hang include: [ - 'vscode', 'vscode/extensions', 'vscode/services', 'vscode/monaco', '@codingame/monaco-vscode-model-service-override', '@codingame/monaco-vscode-editor-service-override', - '@codingame/monaco-vscode-extensions-service-override', '@codingame/monaco-vscode-notifications-service-override', '@codingame/monaco-vscode-bulk-edit-service-override', '@codingame/monaco-vscode-dialogs-service-override', '@codingame/monaco-vscode-configuration-service-override', - '@codingame/monaco-vscode-keybindings-service-override', '@codingame/monaco-vscode-textmate-service-override', '@codingame/monaco-vscode-theme-service-override', '@codingame/monaco-vscode-languages-service-override', - '@codingame/monaco-vscode-audio-cue-service-override', '@codingame/monaco-vscode-views-service-override', '@codingame/monaco-vscode-view-banner-service-override', '@codingame/monaco-vscode-view-status-bar-service-override', '@codingame/monaco-vscode-view-title-bar-service-override', - '@codingame/monaco-vscode-quickaccess-service-override', '@codingame/monaco-vscode-debug-service-override', - '@codingame/monaco-vscode-preferences-service-override', '@codingame/monaco-vscode-snippets-service-override', '@codingame/monaco-vscode-files-service-override', '@codingame/monaco-vscode-output-service-override', - '@codingame/monaco-vscode-terminal-service-override', '@codingame/monaco-vscode-search-service-override', '@codingame/monaco-vscode-markers-service-override', '@codingame/monaco-vscode-accessibility-service-override', '@codingame/monaco-vscode-storage-service-override', - '@codingame/monaco-vscode-language-detection-worker-service-override', '@codingame/monaco-vscode-remote-agent-service-override', '@codingame/monaco-vscode-environment-service-override', '@codingame/monaco-vscode-lifecycle-service-override', - '@codingame/monaco-vscode-workspace-trust-service-override', - '@codingame/monaco-vscode-clojure-default-extension', '@codingame/monaco-vscode-coffeescript-default-extension', '@codingame/monaco-vscode-cpp-default-extension', - '@codingame/monaco-vscode-csharp-default-extension', '@codingame/monaco-vscode-css-default-extension', '@codingame/monaco-vscode-diff-default-extension', '@codingame/monaco-vscode-fsharp-default-extension', '@codingame/monaco-vscode-go-default-extension', - '@codingame/monaco-vscode-groovy-default-extension', '@codingame/monaco-vscode-html-default-extension', '@codingame/monaco-vscode-java-default-extension', '@codingame/monaco-vscode-javascript-default-extension', - '@codingame/monaco-vscode-json-default-extension', '@codingame/monaco-vscode-julia-default-extension', '@codingame/monaco-vscode-lua-default-extension', '@codingame/monaco-vscode-markdown-basics-default-extension', - '@codingame/monaco-vscode-objective-c-default-extension', '@codingame/monaco-vscode-perl-default-extension', '@codingame/monaco-vscode-php-default-extension', '@codingame/monaco-vscode-powershell-default-extension', - '@codingame/monaco-vscode-python-default-extension', '@codingame/monaco-vscode-r-default-extension', '@codingame/monaco-vscode-ruby-default-extension', '@codingame/monaco-vscode-rust-default-extension', - '@codingame/monaco-vscode-scss-default-extension', '@codingame/monaco-vscode-shellscript-default-extension', '@codingame/monaco-vscode-sql-default-extension', '@codingame/monaco-vscode-swift-default-extension', - '@codingame/monaco-vscode-typescript-basics-default-extension', '@codingame/monaco-vscode-vb-default-extension', '@codingame/monaco-vscode-xml-default-extension', '@codingame/monaco-vscode-yaml-default-extension', - '@codingame/monaco-vscode-theme-defaults-default-extension', '@codingame/monaco-vscode-theme-seti-default-extension', - '@codingame/monaco-vscode-references-view-default-extension', '@codingame/monaco-vscode-typescript-basics-default-extension', '@codingame/monaco-vscode-search-result-default-extension', - '@codingame/monaco-vscode-typescript-language-features-default-extension', '@codingame/monaco-vscode-markdown-language-features-default-extension', - '@codingame/monaco-vscode-json-language-features-default-extension', '@codingame/monaco-vscode-css-language-features-default-extension', - '@codingame/monaco-vscode-npm-default-extension', '@codingame/monaco-vscode-css-default-extension', '@codingame/monaco-vscode-markdown-basics-default-extension', '@codingame/monaco-vscode-html-default-extension', - '@codingame/monaco-vscode-html-language-features-default-extension', '@codingame/monaco-vscode-configuration-editing-default-extension', '@codingame/monaco-vscode-media-preview-default-extension', '@codingame/monaco-vscode-markdown-math-default-extension', - '@codingame/monaco-vscode-language-pack-cs', '@codingame/monaco-vscode-language-pack-de', '@codingame/monaco-vscode-language-pack-es', '@codingame/monaco-vscode-language-pack-fr', - '@codingame/monaco-vscode-language-pack-it', '@codingame/monaco-vscode-language-pack-ja', '@codingame/monaco-vscode-language-pack-ko', '@codingame/monaco-vscode-language-pack-pl', - '@codingame/monaco-vscode-language-pack-pt-br', '@codingame/monaco-vscode-language-pack-qps-ploc', '@codingame/monaco-vscode-language-pack-ru', '@codingame/monaco-vscode-language-pack-tr', - '@codingame/monaco-vscode-language-pack-zh-hans', '@codingame/monaco-vscode-language-pack-zh-hant' + // add all local dependencies... + ...Object.entries(pkg.dependencies).filter(([, version]) => version.startsWith('file:../')).map(([name]) => name), + // and their exports + 'vscode/extensions', 'vscode/services', 'vscode/monaco', + + // These 2 lines prevent vite from reloading the whole page when starting a worker (so 2 times in a row after cleaning the vite cache - for the editor then the textmate workers) + // it's mainly empirical and probably not the best way, fix me if you find a better way + 'monaco-editor/esm/vs/nls.js', 'monaco-editor/esm/vs/editor/editor.worker.js', 'vscode-textmate', 'vscode-oniguruma', '@vscode/vscode-languagedetection', + ...(await glob('monaco-editor/esm/vs/**/common/**/*.js', { cwd: path.resolve(__dirname, '../node_modules') })), ], + exclude: [], esbuildOptions: { plugins: [{ name: 'import.meta.url',