@@ -6,24 +6,37 @@ const name = pkg.name
66 . split ( '-' )
77 . map ( ( s ) => s . charAt ( 0 ) . toUpperCase ( ) + s . slice ( 1 ) )
88 . join ( '' ) ;
9- const requirePolyfills = process . env . INCLUDE_POLYFILLS ;
10- export default {
11- input : requirePolyfills ? 'lib/esm-including-polyfills/index.js' : 'lib/esm/index.js' ,
12- output : {
13- file : requirePolyfills
14- ? 'dist/stringToReactComponent.including-polyfills.umd.min.js'
15- : 'dist/stringToReactComponent.umd.min.js' ,
16- format : 'umd' ,
17- name,
18- globals : {
19- 'react-dom' : 'ReactDOM' ,
20- react : 'React' ,
21- '@babel/standalone' : 'Babel' ,
22- } ,
23- sourcemap : true ,
9+ const Config = ( { en, inputPath = '' , outputFile = 'stringToReactComponent' , pf = false } ) => {
10+ var pfName = pf ? '.including-polyfills' : '' ;
11+ return {
12+ input : `lib/${ pf ? 'esm-including-polyfills' : 'esm' } /${ inputPath } index.js` ,
13+ output : {
14+ file : `dist/${ outputFile } ${ pfName } .umd${ en === 'dev' ? '' : '.min' } .js` ,
15+ format : 'umd' ,
16+ name,
17+ globals : {
18+ 'react-dom' : 'ReactDOM' ,
19+ react : 'React' ,
20+ '@babel/standalone' : 'Babel' ,
21+ } ,
22+ sourcemap : true ,
23+ } ,
24+ plugins : ( function ( ) {
25+ const _plugins = [ nodeResolve ( { preferBuiltins : false } ) , commonjs ( ) ] ;
26+ if ( en === 'prod' ) {
27+ _plugins . push ( terser ( ) ) ;
28+ }
29+ return _plugins ;
30+ } ) ( ) ,
31+ external : function ( id ) {
32+ return / p r o p - t y p e s $ | r e a c t $ | \@ b a b e l \/ s t a n d a l o n e $ | r e a c t - d o m $ | .t e s t .j s $ | .j s .s n a p $ | .c s s $ / g. test ( id ) ;
33+ } ,
34+ } ;
2435 } ,
25- plugins : [ terser ( ) , commonjs ( ) , nodeResolve ( { preferBuiltins : false } ) ] ,
26- external : function ( id ) {
27- return / p r o p - t y p e s $ | r e a c t $ | \@ b a b e l \/ s t a n d a l o n e $ | r e a c t - d o m $ | .t e s t .j s $ | .j s .s n a p $ | .c s s $ / g. test ( id ) ;
28- } ,
29- } ;
36+ ConfigFactory = ( op ) => [
37+ Config ( { en : 'dev' , ...op } ) ,
38+ Config ( { en : 'prod' , ...op } ) ,
39+ Config ( { en : 'dev' , pf : true , ...op } ) ,
40+ Config ( { en : 'prod' , pf : true , ...op } ) ,
41+ ] ;
42+ export default ConfigFactory ( ) ;
0 commit comments