@@ -3,7 +3,7 @@ const {mkdir, writeFile} = require('fs');
33const { dirname, resolve} = require ( 'path' ) ;
44const { rollup} = require ( 'rollup' ) ;
55const { promisify} = require ( 'util' ) ;
6- const config = require ( '../rollup.config' ) ;
6+ const configs = require ( '../rollup.config' ) ;
77
88const mkdirAsync = promisify ( mkdir ) ;
99const writeFileAsync = promisify ( writeFile ) ;
@@ -13,19 +13,25 @@ const detection = ' if (detect()) { return; }';
1313
1414( async ( ) => {
1515 try {
16- const bundle = await rollup ( config ) ;
17- const generated = await bundle . generate ( config . output ) ;
18- const {
19- output : [ { code} ] ,
20- } = generated ;
16+ await Promise . all (
17+ configs . map ( async ( config , index ) => {
18+ const bundle = await rollup ( config ) ;
19+ const generated = await bundle . generate ( config . output ) ;
20+ let {
21+ output : [ { code} ] ,
22+ } = generated ;
2123
22- const [ first , second , ...other ] = code . split ( '\n' ) ;
23- const result = [ first , second , detection , ...other ] . join ( '\n' ) ;
24+ if ( index === 0 ) {
25+ const [ first , second , ...other ] = code . split ( '\n' ) ;
26+ code = [ first , second , detection , ...other ] . join ( '\n' ) ;
27+ }
2428
25- const resultFile = resolve ( cwd , config . output . file ) ;
29+ const resultFile = resolve ( cwd , config . output . file ) ;
2630
27- await mkdirAsync ( dirname ( resultFile ) , { recursive : true } ) ;
28- await writeFileAsync ( resultFile , result , 'utf8' ) ;
31+ await mkdirAsync ( dirname ( resultFile ) , { recursive : true } ) ;
32+ await writeFileAsync ( resultFile , code , 'utf8' ) ;
33+ } ) ,
34+ ) ;
2935 } catch ( e ) {
3036 console . error ( e . stack ) ;
3137 process . exit ( 1 ) ;
0 commit comments