@@ -16,6 +16,7 @@ import {
1616 makeCleanupPlugin ,
1717 makeDebugBuildStatementReplacePlugin ,
1818 makeNodeResolvePlugin ,
19+ makeProductionReplacePlugin ,
1920 makeRrwebBuildPlugin ,
2021 makeSucrasePlugin ,
2122} from './plugins/index.mjs' ;
@@ -114,22 +115,47 @@ export function makeBaseNPMConfig(options = {}) {
114115}
115116
116117export function makeNPMConfigVariants ( baseConfig , options = { } ) {
117- const { emitEsm = true , emitCjs = true } = options ;
118+ const { emitEsm = true , emitCjs = true , splitDevProd = false } = options ;
118119
119120 const variantSpecificConfigs = [ ] ;
120121
121122 if ( emitCjs ) {
122- variantSpecificConfigs . push ( { output : { format : 'cjs' , dir : path . join ( baseConfig . output . dir , 'cjs' ) } } ) ;
123+ if ( splitDevProd ) {
124+ variantSpecificConfigs . push ( { output : { format : 'cjs' , dir : path . join ( baseConfig . output . dir , 'cjs/dev' ) } } ) ;
125+ variantSpecificConfigs . push ( {
126+ output : { format : 'cjs' , dir : path . join ( baseConfig . output . dir , 'cjs/prod' ) } ,
127+ plugins : [ makeProductionReplacePlugin ( ) ]
128+ } ) ;
129+ } else {
130+ variantSpecificConfigs . push ( { output : { format : 'cjs' , dir : path . join ( baseConfig . output . dir , 'cjs' ) } } ) ;
131+ }
123132 }
124133
125134 if ( emitEsm ) {
126- variantSpecificConfigs . push ( {
127- output : {
128- format : 'esm' ,
129- dir : path . join ( baseConfig . output . dir , 'esm' ) ,
130- plugins : [ makePackageNodeEsm ( ) ] ,
131- } ,
132- } ) ;
135+ if ( splitDevProd ) {
136+ variantSpecificConfigs . push ( {
137+ output : {
138+ format : 'esm' ,
139+ dir : path . join ( baseConfig . output . dir , 'esm/dev' ) ,
140+ plugins : [ makePackageNodeEsm ( ) ] ,
141+ } ,
142+ } ) ;
143+ variantSpecificConfigs . push ( {
144+ output : {
145+ format : 'esm' ,
146+ dir : path . join ( baseConfig . output . dir , 'esm/prod' ) ,
147+ plugins : [ makeProductionReplacePlugin ( ) , makePackageNodeEsm ( ) ] ,
148+ } ,
149+ } ) ;
150+ } else {
151+ variantSpecificConfigs . push ( {
152+ output : {
153+ format : 'esm' ,
154+ dir : path . join ( baseConfig . output . dir , 'esm' ) ,
155+ plugins : [ makePackageNodeEsm ( ) ] ,
156+ } ,
157+ } ) ;
158+ }
133159 }
134160
135161 return variantSpecificConfigs . map ( variant => deepMerge ( baseConfig , variant ) ) ;
0 commit comments