diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 84f2ebdb4f..38127d0333 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -563,6 +563,7 @@ "postinstall": "vscode-ext-gen --scope vue" }, "devDependencies": { + "@kermanx/tree-shaker": "https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker@93d12c6", "@types/semver": "^7.5.3", "@types/vscode": "^1.82.0", "@volar/vscode": "~2.4.11", diff --git a/extensions/vscode/scripts/build.js b/extensions/vscode/scripts/build.js index 39acc64a1f..2266d7abce 100644 --- a/extensions/vscode/scripts/build.js +++ b/extensions/vscode/scripts/build.js @@ -1,8 +1,11 @@ // @ts-check const path = require('path'); const fs = require('fs'); +const esbuild = require('esbuild'); +const { treeShake } = require('@kermanx/tree-shaker'); +const minify = process.argv.includes('--minify'); -require('esbuild').context({ +esbuild.context({ entryPoints: { 'dist/client': './out/nodeClientMain.js', 'dist/server': './node_modules/@vue/language-server/bin/vue-language-server.js', @@ -17,7 +20,7 @@ require('esbuild').context({ platform: 'node', tsconfig: './tsconfig.json', define: { 'process.env.NODE_ENV': '"production"' }, - minify: process.argv.includes('--minify'), + minify: minify, plugins: [ { name: 'umd2esm', @@ -79,15 +82,35 @@ require('esbuild').context({ }); }, }, + { + name: 'tree-shaking', + setup(build) { + if (!minify) { + return; + } + build.onLoad({ filter: /\.js$/ }, ({ path }) => { + path = path.replace(/\\/g, '/'); + const source = fs.readFileSync(path, 'utf-8'); + const { output, diagnostics } = treeShake(source, 'recommended', false); + if (!diagnostics.length) { + return { + contents: output, + loader: 'js', + } + } + }); + }, + }, ], }).then(async ctx => { - console.log('building...'); + console.time('build'); if (process.argv.includes('--watch')) { await ctx.watch(); + console.timeEnd('build'); console.log('watching...'); } else { await ctx.rebuild(); await ctx.dispose(); - console.log('finished.'); + console.timeEnd('build'); } }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 798a4265fb..1339e048ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: extensions/vscode: devDependencies: + '@kermanx/tree-shaker': + specifier: https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker@93d12c6 + version: https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker@93d12c6 '@types/semver': specifier: ^7.5.3 version: 7.5.8 @@ -745,6 +748,34 @@ packages: '@jridgewell/sourcemap-codec@1.5.0': resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} + '@kermanx/tree-shaker-darwin-arm64@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-arm64@93d12c6d4de524b41b0bded00e91760e7946cc9b': + resolution: {tarball: https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-arm64@93d12c6d4de524b41b0bded00e91760e7946cc9b} + version: 0.0.0 + engines: {node: '>= 10'} + os: [darwin] + + '@kermanx/tree-shaker-darwin-x64@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-x64@93d12c6d4de524b41b0bded00e91760e7946cc9b': + resolution: {tarball: https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-x64@93d12c6d4de524b41b0bded00e91760e7946cc9b} + version: 0.0.0 + engines: {node: '>= 10'} + os: [darwin] + + '@kermanx/tree-shaker-linux-x64-gnu@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-linux-x64-gnu@93d12c6d4de524b41b0bded00e91760e7946cc9b': + resolution: {tarball: https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-linux-x64-gnu@93d12c6d4de524b41b0bded00e91760e7946cc9b} + version: 0.0.0 + engines: {node: '>= 10'} + os: [linux] + + '@kermanx/tree-shaker-win32-x64-msvc@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-win32-x64-msvc@93d12c6d4de524b41b0bded00e91760e7946cc9b': + resolution: {tarball: https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-win32-x64-msvc@93d12c6d4de524b41b0bded00e91760e7946cc9b} + version: 0.0.0 + engines: {node: '>= 10'} + os: [win32] + + '@kermanx/tree-shaker@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker@93d12c6': + resolution: {tarball: https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker@93d12c6} + version: 0.0.0 + '@lerna-lite/cli@3.10.1': resolution: {integrity: sha512-T7wFyKpH8YaXADadqYMyIl5n3ZNSGNXxCiy+KodHqLmeUlMzUGb57zL3QvZ2k/yqotJGIhc7m9FGhdwh0kfDgA==} engines: {node: ^18.0.0 || >=20.0.0} @@ -2221,8 +2252,8 @@ packages: resolution: {integrity: sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==} hasBin: true - math-intrinsics@1.0.0: - resolution: {integrity: sha512-4MqMiKP90ybymYvsut0CH2g4XWbfLtmlCkXmtmdcDCxNB+mQcu1w/1+L/VD7vi/PSv7X2JYV7SCcR+jiPXnQtA==} + math-intrinsics@1.1.0: + resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==} engines: {node: '>= 0.4'} mdurl@2.0.0: @@ -2449,8 +2480,8 @@ packages: resolution: {integrity: sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - p-limit@6.1.0: - resolution: {integrity: sha512-H0jc0q1vOzlEk0TqAKXKZxdl7kX3OFUzCnNVUnq5Pc3DGo0kpeaMuPqxQn235HibwBEb0/pm9dgKTjXy66fBkg==} + p-limit@6.2.0: + resolution: {integrity: sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA==} engines: {node: '>=18'} p-locate@4.1.0: @@ -3709,6 +3740,25 @@ snapshots: '@jridgewell/sourcemap-codec@1.5.0': {} + '@kermanx/tree-shaker-darwin-arm64@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-arm64@93d12c6d4de524b41b0bded00e91760e7946cc9b': + optional: true + + '@kermanx/tree-shaker-darwin-x64@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-x64@93d12c6d4de524b41b0bded00e91760e7946cc9b': + optional: true + + '@kermanx/tree-shaker-linux-x64-gnu@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-linux-x64-gnu@93d12c6d4de524b41b0bded00e91760e7946cc9b': + optional: true + + '@kermanx/tree-shaker-win32-x64-msvc@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-win32-x64-msvc@93d12c6d4de524b41b0bded00e91760e7946cc9b': + optional: true + + '@kermanx/tree-shaker@https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker@93d12c6': + optionalDependencies: + '@kermanx/tree-shaker-darwin-arm64': https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-arm64@93d12c6d4de524b41b0bded00e91760e7946cc9b + '@kermanx/tree-shaker-darwin-x64': https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-darwin-x64@93d12c6d4de524b41b0bded00e91760e7946cc9b + '@kermanx/tree-shaker-linux-x64-gnu': https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-linux-x64-gnu@93d12c6d4de524b41b0bded00e91760e7946cc9b + '@kermanx/tree-shaker-win32-x64-msvc': https://pkg.pr.new/KermanX/tree-shaker/@kermanx/tree-shaker-win32-x64-msvc@93d12c6d4de524b41b0bded00e91760e7946cc9b + '@lerna-lite/cli@3.10.1(@lerna-lite/publish@3.10.1(@types/node@22.10.2)(typescript@5.7.2))(@lerna-lite/version@3.10.1(@lerna-lite/publish@3.10.1(@types/node@22.10.2)(typescript@5.7.2))(@types/node@22.10.2)(typescript@5.7.2))(@types/node@22.10.2)(typescript@5.7.2)': dependencies: '@lerna-lite/core': 3.10.1(@types/node@22.10.2)(typescript@5.7.2) @@ -3854,7 +3904,7 @@ snapshots: new-github-release-url: 2.0.0 node-fetch: 3.3.2 npm-package-arg: 11.0.3 - p-limit: 6.1.0 + p-limit: 6.2.0 p-map: 7.0.3 p-pipe: 4.0.0 p-reduce: 3.0.0 @@ -5125,7 +5175,7 @@ snapshots: gopd: 1.2.0 has-symbols: 1.1.0 hasown: 2.0.2 - math-intrinsics: 1.0.0 + math-intrinsics: 1.1.0 get-stream@8.0.1: {} @@ -5523,7 +5573,7 @@ snapshots: punycode.js: 2.3.1 uc.micro: 2.1.0 - math-intrinsics@1.0.0: {} + math-intrinsics@1.1.0: {} mdurl@2.0.0: {} @@ -5750,7 +5800,7 @@ snapshots: dependencies: yocto-queue: 1.1.1 - p-limit@6.1.0: + p-limit@6.2.0: dependencies: yocto-queue: 1.1.1 diff --git a/tsconfig.json b/tsconfig.json index a273185343..504507e0ea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,13 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { + "allowJs": true, "noEmit": true, }, - "include": [ "packages/*/tests" ], + "include": [ + "packages/*/tests", + "extensions/vscode/scripts/build.js", + ], "references": [ { "path": "./extensions/vscode/tsconfig.json" }, { "path": "./packages/language-plugin-pug/tsconfig.json" },