1
- import { BuildContext , BuildState , ChangedFile , TaskInfo } from './util/interfaces' ;
2
- import { BuildError } from './util/errors' ;
3
- import { fillConfigDefaults , getUserConfigFile , replacePathVars } from './util/config' ;
4
- import { ionicRollupResolverPlugin , PLUGIN_NAME } from './rollup/ionic-rollup-resolver-plugin' ;
5
1
import { join , isAbsolute , normalize , sep } from 'path' ;
6
- import { Logger } from './logger/logger' ;
7
2
import * as rollupBundler from 'rollup' ;
8
3
4
+ import { Logger } from './logger/logger' ;
5
+ import { ionicRollupResolverPlugin , PLUGIN_NAME } from './rollup/ionic-rollup-resolver-plugin' ;
6
+ import { fillConfigDefaults , getUserConfigFile , replacePathVars } from './util/config' ;
7
+ import { BuildError } from './util/errors' ;
8
+ import { writeFileAsync } from './util/helpers' ;
9
+ import { BuildContext , BuildState , ChangedFile , TaskInfo } from './util/interfaces' ;
10
+
9
11
10
12
export function rollup ( context : BuildContext , configFile : string ) {
11
13
configFile = getUserConfigFile ( context , taskInfo , configFile ) ;
@@ -67,6 +69,7 @@ export function rollupWorker(context: BuildContext, configFile: string): Promise
67
69
rollupBundler . rollup ( rollupConfig )
68
70
. then ( ( bundle : RollupBundle ) => {
69
71
72
+
70
73
Logger . debug ( `bundle.modules: ${ bundle . modules . length } ` ) ;
71
74
72
75
// set the module files used in this bundle
@@ -85,8 +88,18 @@ export function rollupWorker(context: BuildContext, configFile: string): Promise
85
88
cachedBundle = bundle ;
86
89
}
87
90
91
+ const bundleOutput = bundle . generate ( {
92
+ format : rollupConfig . format
93
+ } ) ;
94
+
88
95
// write the bundle
89
- return bundle . write ( rollupConfig ) ;
96
+ const jsFileToWrite = join ( context . buildDir , rollupConfig . dest ) ;
97
+ const promises : Promise < any > [ ] = [ ] ;
98
+ promises . push ( writeFileAsync ( jsFileToWrite , bundleOutput . code ) ) ;
99
+ if ( bundleOutput . map ) {
100
+ promises . push ( writeFileAsync ( jsFileToWrite + '.map' , bundleOutput . map ) ) ;
101
+ }
102
+ return Promise . all ( promises ) ;
90
103
} )
91
104
. then ( ( ) => {
92
105
// clean up any references (overkill yes, but let's play it safe)
@@ -183,8 +196,14 @@ export interface RollupBundle {
183
196
// https://github.com/rollup/rollup/wiki/JavaScript-API
184
197
write ?: Function ;
185
198
modules : RollupModule [ ] ;
199
+ generate : ( config : RollupConfig ) => RollupBundleOutput ;
186
200
} ;
187
201
202
+ export interface RollupBundleOutput {
203
+ code : string ;
204
+ map : string ;
205
+ }
206
+
188
207
189
208
export interface RollupModule {
190
209
id : string ;
0 commit comments