@@ -115,6 +115,18 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {
115115
116116 const variantSpecificConfigs = [ ] ;
117117
118+ // Determine the correct types output directory based on hasBundles
119+ // hasBundles packages output to build/npm/, so types go to build/npm/types
120+ // Regular packages output to build/, so types go to build/types
121+ const typesOutDir = baseConfig . output . dir === 'build/npm' ? 'build/npm/types' : 'build/types' ;
122+
123+ const dtsPlugin = dts ( {
124+ tsconfig : path . resolve ( process . cwd ( ) , './tsconfig.types.json' ) ,
125+ compilerOptions : {
126+ outDir : typesOutDir ,
127+ } ,
128+ } ) ;
129+
118130 if ( emitCjs ) {
119131 if ( splitDevProd ) {
120132 variantSpecificConfigs . push ( { output : { format : 'cjs' , dir : path . join ( baseConfig . output . dir , 'cjs/dev' ) } } ) ;
@@ -129,11 +141,12 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {
129141
130142 if ( emitEsm ) {
131143 if ( splitDevProd ) {
144+ // Add dts plugin to the dev ESM build (only needs to run once)
132145 variantSpecificConfigs . push ( {
133146 output : {
134147 format : 'esm' ,
135148 dir : path . join ( baseConfig . output . dir , 'esm/dev' ) ,
136- plugins : [ makePackageNodeEsm ( ) ] ,
149+ plugins : [ makePackageNodeEsm ( ) , dtsPlugin ] ,
137150 } ,
138151 } ) ;
139152 variantSpecificConfigs . push ( {
@@ -144,13 +157,6 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {
144157 } ,
145158 } ) ;
146159 } else {
147- const dtsPlugin = dts ( {
148- tsconfig : path . resolve ( process . cwd ( ) , './tsconfig.types.json' ) ,
149- compilerOptions : {
150- outDir : 'build/types' ,
151- } ,
152- } ) ;
153-
154160 variantSpecificConfigs . push ( {
155161 output : {
156162 format : 'esm' ,
0 commit comments