@@ -35,15 +35,21 @@ const external = [
35
35
36
36
export default defineConfig ( {
37
37
input : {
38
- index : './temp/ src/node/index.d .ts' ,
39
- 'module-runner' : './temp/ src/module-runner/index.d .ts' ,
38
+ index : './src/node/index.ts' ,
39
+ 'module-runner' : './src/module-runner/index.ts' ,
40
40
} ,
41
41
output : {
42
42
dir : './dist/node' ,
43
43
format : 'esm' ,
44
44
} ,
45
+ treeshake : {
46
+ moduleSideEffects : 'no-external' ,
47
+ } ,
45
48
external,
46
- plugins : [ patchTypes ( ) , dts ( { dtsInput : true } ) ] ,
49
+ plugins : [
50
+ patchTypes ( ) ,
51
+ dts ( { tsconfig : './src/node/tsconfig.build.json' , emitDtsOnly : true } ) ,
52
+ ] ,
47
53
} )
48
54
49
55
// Taken from https://stackoverflow.com/a/36328890
@@ -114,7 +120,7 @@ function patchTypes(): Plugin {
114
120
resolveId : {
115
121
order : 'pre' ,
116
122
filter : {
117
- id : / ^ ( d e p - ) * t y p e s \/ / ,
123
+ id : / ^ ( d e p - ) ? t y p e s \/ / ,
118
124
} ,
119
125
handler ( id ) {
120
126
// Dep types should be bundled
@@ -134,26 +140,29 @@ function patchTypes(): Plugin {
134
140
}
135
141
} ,
136
142
} ,
137
- generateBundle ( _opts , bundle ) {
138
- for ( const chunk of Object . values ( bundle ) ) {
139
- if ( chunk . type !== 'chunk' ) continue
143
+ generateBundle : {
144
+ order : 'post' ,
145
+ handler ( _opts , bundle ) {
146
+ for ( const chunk of Object . values ( bundle ) ) {
147
+ if ( chunk . type !== 'chunk' ) continue
140
148
141
- const ast = parseAst ( chunk . code , { lang : 'ts' , sourceType : 'module' } )
142
- const importBindings = getAllImportBindings ( ast )
143
- if (
144
- chunk . fileName . startsWith ( 'module-runner' ) ||
145
- // index and moduleRunner have a common chunk "moduleRunnerTransport"
146
- chunk . fileName . startsWith ( 'moduleRunnerTransport' ) ||
147
- chunk . fileName . startsWith ( 'types.d-' )
148
- ) {
149
- validateRunnerChunk . call ( this , chunk , importBindings )
150
- } else {
151
- validateChunkImports . call ( this , chunk , importBindings )
152
- replaceConfusingTypeNames . call ( this , chunk , importBindings )
153
- stripInternalTypes . call ( this , chunk )
154
- cleanUnnecessaryComments ( chunk )
149
+ const ast = parseAst ( chunk . code , { lang : 'ts' , sourceType : 'module' } )
150
+ const importBindings = getAllImportBindings ( ast )
151
+ if (
152
+ chunk . fileName . startsWith ( 'module-runner' ) ||
153
+ // index and moduleRunner have a common chunk "moduleRunnerTransport"
154
+ chunk . fileName . startsWith ( 'moduleRunnerTransport' ) ||
155
+ chunk . fileName . startsWith ( 'types.d-' )
156
+ ) {
157
+ validateRunnerChunk . call ( this , chunk , importBindings )
158
+ } else {
159
+ validateChunkImports . call ( this , chunk , importBindings )
160
+ replaceConfusingTypeNames . call ( this , chunk , importBindings )
161
+ stripInternalTypes . call ( this , chunk )
162
+ cleanUnnecessaryComments ( chunk )
163
+ }
155
164
}
156
- }
165
+ } ,
157
166
} ,
158
167
}
159
168
}
0 commit comments