Skip to content

Commit f786da7

Browse files
committed
chore: only build server and typescript plugin at production
1 parent 505a669 commit f786da7

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

extensions/vscode/rolldown.config.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
11
import * as fs from 'node:fs';
22
import * as path from 'node:path';
3-
import { defineConfig } from 'rolldown';
3+
import { defineConfig, type RolldownOptions } from 'rolldown';
44

5+
const isDev = !process.argv.includes('--minify');
56
const resolve = (...paths: string[]) => path.resolve(__dirname, ...paths);
67

7-
export default defineConfig({
8+
const config: RolldownOptions = {
89
input: {
910
'client': './src/nodeClientMain.ts',
10-
'server': './node_modules/@vue/language-server/node.ts',
11-
'plugin': './node_modules/@vue/typescript-plugin/index.ts',
1211
},
1312
output: {
1413
format: 'cjs',
15-
sourcemap: !process.argv.includes('--minify'),
14+
sourcemap: isDev,
1615
},
1716
define: {
1817
'process.env.NODE_ENV': '"production"',
1918
},
2019
external: ['vscode'],
2120
plugins: [
22-
{
23-
name: 'umd2esm',
24-
resolveId: {
25-
filter: {
26-
id: /^(vscode-.*-languageservice|vscode-languageserver-types|jsonc-parser)$/,
27-
},
28-
handler(source, importer) {
29-
const pathUmdMay = require.resolve(source, { paths: [importer!] });
30-
// Call twice the replace is to solve the problem of the path in Windows
31-
const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\');
32-
return { id: pathEsm };
33-
},
34-
},
35-
},
3621
{
3722
name: 'clean',
3823
buildStart() {
@@ -50,12 +35,40 @@ export default defineConfig({
5035
},
5136
},
5237
{
53-
name: 'typescript-plugin',
38+
name: 'redirect',
5439
buildEnd() {
55-
const dir = './node_modules/vue-typescript-plugin-pack';
56-
fs.mkdirSync(resolve(dir), { recursive: true });
57-
fs.writeFileSync(resolve(dir, 'index.js'), `module.exports = require('../../dist/plugin.js');`);
40+
fs.mkdirSync(resolve('./node_modules/vue-typescript-plugin-pack'), { recursive: true });
41+
fs.writeFileSync(resolve('./node_modules/vue-typescript-plugin-pack/index.js'), `module.exports = require('../../dist/plugin.js');`);
42+
43+
if (isDev) {
44+
fs.writeFileSync(resolve('./dist/server.js'), `module.exports = require('../node_modules/@vue/language-server/node.js');`);
45+
fs.writeFileSync(resolve('./dist/plugin.js'), `module.exports = require('../node_modules/@vue/typescript-plugin/index.js');`);
46+
}
47+
},
48+
},
49+
{
50+
name: 'umd2esm',
51+
resolveId: {
52+
filter: {
53+
id: /^(vscode-.*-languageservice|vscode-languageserver-types|jsonc-parser)$/,
54+
},
55+
handler(source, importer) {
56+
const pathUmdMay = require.resolve(source, { paths: [importer!] });
57+
// Call twice the replace is to solve the problem of the path in Windows
58+
const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\');
59+
return { id: pathEsm };
60+
},
5861
},
5962
},
6063
],
61-
});
64+
};
65+
66+
if (!isDev) {
67+
config.input = {
68+
...config.input as Record<string, string>,
69+
'server': './node_modules/@vue/language-server/node.js',
70+
'plugin': './node_modules/@vue/typescript-plugin/index.js',
71+
};
72+
}
73+
74+
export default defineConfig(config);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"packageManager": "pnpm@10.4.1",
44
"scripts": {
55
"build": "tsc -b",
6-
"watch": "cd ./extensions/vscode && pnpm run watch",
6+
"watch": "pnpm run \"/^watch:.*/\"",
7+
"watch:base": "tsc -b -w",
8+
"watch:vue": "cd ./extensions/vscode && pnpm run watch",
79
"prerelease": "pnpm run build && pnpm run test",
810
"release": "pnpm run release:base && pnpm run release:vue",
911
"release:base": "lerna publish --exact --force-publish --yes --sync-workspace-lock --no-git-tag-version",

0 commit comments

Comments
 (0)