11import * as fs from 'node:fs' ;
22import * 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' ) ;
56const resolve = ( ...paths : string [ ] ) => path . resolve ( __dirname , ...paths ) ;
67
7- export default defineConfig ( {
8+ const config : RolldownOptions = {
89input : {
910'client' : './src/nodeClientMain.ts' ,
10- 'server' : './node_modules/@vue/language-server/node.ts' ,
11- 'plugin' : './node_modules/@vue/typescript-plugin/index.ts' ,
1211} ,
1312output : {
1413format : 'cjs' ,
15- sourcemap : ! process . argv . includes ( '--minify' ) ,
14+ sourcemap : isDev ,
1615} ,
1716define : {
1817'process.env.NODE_ENV' : '"production"' ,
1918} ,
2019external : [ 'vscode' ] ,
2120plugins : [
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- } ,
3621{
3722name : 'clean' ,
3823buildStart ( ) {
@@ -50,12 +35,40 @@ export default defineConfig({
5035} ,
5136} ,
5237{
53- name : 'typescript-plugin ' ,
38+ name : 'redirect ' ,
5439buildEnd ( ) {
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+ } ,
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 ) ;
0 commit comments