1
1
import * as fs from 'node:fs' ;
2
2
import * as path from 'node:path' ;
3
- import { defineConfig } from 'rolldown' ;
3
+ import { defineConfig , type RolldownOptions } from 'rolldown' ;
4
4
5
+ const isDev = ! process . argv . includes ( '--minify' ) ;
5
6
const resolve = ( ...paths : string [ ] ) => path . resolve ( __dirname , ...paths ) ;
6
7
7
- export default defineConfig ( {
8
+ const config : RolldownOptions = {
8
9
input : {
9
10
'client' : './src/nodeClientMain.ts' ,
10
- 'server' : './node_modules/@vue/language-server/node.ts' ,
11
- 'plugin' : './node_modules/@vue/typescript-plugin/index.ts' ,
12
11
} ,
13
12
output : {
14
13
format : 'cjs' ,
15
- sourcemap : ! process . argv . includes ( '--minify' ) ,
14
+ sourcemap : isDev ,
16
15
} ,
17
16
define : {
18
17
'process.env.NODE_ENV' : '"production"' ,
19
18
} ,
20
19
external : [ 'vscode' ] ,
21
20
plugins : [
22
- {
23
- name : 'umd2esm' ,
24
- resolveId : {
25
- filter : {
26
- id : / ^ ( v s c o d e - .* - l a n g u a g e s e r v i c e | v s c o d e - l a n g u a g e s e r v e r - t y p e s | j s o n c - p a r s e r ) $ / ,
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
- } ,
36
21
{
37
22
name : 'clean' ,
38
23
buildStart ( ) {
@@ -50,12 +35,40 @@ export default defineConfig({
50
35
} ,
51
36
} ,
52
37
{
53
- name : 'typescript-plugin ' ,
38
+ name : 'redirect ' ,
54
39
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 : / ^ ( v s c o d e - .* - l a n g u a g e s e r v i c e | v s c o d e - l a n g u a g e s e r v e r - t y p e s | j s o n c - p a r s e r ) $ / ,
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
+ } ,
58
61
} ,
59
62
} ,
60
63
] ,
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 ) ;
0 commit comments