1+ import { appendFileSync } from 'fs' ;
12import { join } from 'path' ;
23import * as Builder from 'systemjs-builder' ;
34
@@ -28,24 +29,37 @@ const normalizeConfig = (bundles: any[]) => {
2829 } ) ;
2930} ;
3031
32+ const addExtensions = `
33+ System.config({ defaultJSExtensions: true });
34+ (function () {
35+ Object.keys(System.defined).forEach(function (m) {
36+ if (!/\.js$/.test(m)) {
37+ System.defined[m + '.js'] = System.defined[m];
38+ }
39+ });
40+ }());
41+ ` ;
42+
3143const bundleMain = ( ) => {
32- let builder = new Builder ( Config . SYSTEM_BUILDER_CONFIG ) ;
44+ const builder = new Builder ( Config . SYSTEM_BUILDER_CONFIG ) ;
45+ const mainpath = join ( Config . TMP_DIR , Config . BOOTSTRAP_PROD_MODULE ) ;
46+ const outpath = join ( Config . JS_DEST , Config . JS_PROD_APP_BUNDLE ) ;
3347 return builder
34- . buildStatic ( join ( Config . TMP_DIR , Config . BOOTSTRAP_PROD_MODULE ) ,
35- join ( Config . JS_DEST , Config . JS_PROD_APP_BUNDLE ) ,
36- BUNDLER_OPTIONS ) ;
48+ . bundle ( mainpath ,
49+ outpath ,
50+ Object . assign ( { format : 'umd' , BUNDLER_OPTIONS } ) )
51+ . then ( ( res : any ) => {
52+ appendFileSync ( outpath , `System.import('${ mainpath } .js');${ addExtensions } ` ) ;
53+ return res . modules ;
54+ } ) ;
3755} ;
3856
39- const bundleModule = ( config : Bundle [ ] , bundle : Bundle ) => {
40- const rest = config . filter ( b => b !== bundle ) ;
57+ const bundleModule = ( config : Bundle [ ] , exclude : string [ ] , bundle : Bundle ) => {
4158 let builder = new Builder ( Config . SYSTEM_BUILDER_CONFIG ) ;
4259 let all = join ( Config . TMP_DIR , Config . BOOTSTRAP_DIR ) ;
43- let restModules = rest . map ( b => {
44- return join ( Config . TMP_DIR , Config . BOOTSTRAP_DIR , b . path , b . module ) ;
45- } ) . join ( ' + ' ) ;
4660 let bootstrap = join ( Config . TMP_DIR , Config . BOOTSTRAP_DIR , bundle . path , bundle . module ) ;
4761 let bootstrapDir = join ( Config . TMP_DIR , Config . BOOTSTRAP_DIR , bundle . path ) ;
48- let expression = `${ bootstrap } - (${ all } /**/*.js - ${ bootstrapDir } /**/*.js)` ;
62+ let expression = `${ bootstrap } - (${ all } /**/*.js - ${ bootstrapDir } /**/*.js) - ${ exclude . join ( ' - ' ) } ` ;
4963 console . log ( 'bundling' , expression ) ;
5064 return builder
5165 . buildStatic (
@@ -65,7 +79,7 @@ const bundleModule = (config: Bundle[], bundle: Bundle) => {
6579export = ( done : any ) => {
6680 const config = normalizeConfig ( Config . BUNDLES ) ;
6781 bundleMain ( )
68- . then ( ( ) => Promise . all ( config . map ( bundleModule . bind ( null , config ) ) ) )
82+ . then ( ( bundled : string [ ] ) => Promise . all ( config . map ( bundleModule . bind ( null , config , bundled ) ) ) )
6983 . then ( ( ) => done ( ) )
7084 . catch ( ( e : any ) => done ( e ) ) ;
7185} ;
0 commit comments