11'use strict' ;
2+ const path = require ( 'path' ) ;
23
34exports . createLoaderCode = function createLoaderCode ( platform , bundler ) {
45 let loaderCode ;
@@ -9,7 +10,7 @@ exports.createLoaderCode = function createLoaderCode(platform, bundler) {
910 loaderCode = 'requirejs.config(' + JSON . stringify ( exports . createRequireJSConfig ( platform , bundler ) ) + ')' ;
1011 break ;
1112 case 'system' :
12- loaderCode = exports . createSystemJSConfig ( platform ) ;
13+ loaderCode = 'window.define=SystemJS.amdDefine; window.require=window.requirejs=SystemJS.amdRequire; SystemJS.config(' + JSON . stringify ( exports . createSystemJSConfig ( platform , bundler ) ) + ');' ;
1314 break ;
1415 default :
1516 //TODO: Enhancement: Look at a designated folder for any custom configurations
@@ -76,8 +77,18 @@ exports.createRequireJSConfig = function createRequireJSConfig(platform, bundler
7677 return config ;
7778} ;
7879
79- exports . createSystemJSConfig = function createSystemJSConfig ( platform ) {
80- throw new Error ( 'SystemJS is not yet supported' ) ;
80+ exports . createSystemJSConfig = function createSystemJSConfig ( platform , bundler ) {
81+ const loaderOptions = bundler . loaderOptions ;
82+ const bundles = bundler . bundles ;
83+ const configBundleName = loaderOptions . configTarget ;
84+ const includeBundles = shouldIncludeBundleMetadata ( bundles , loaderOptions ) ;
85+ const location = platform . baseUrl || platform . output ;
86+
87+ const config = bundles . map ( bundle => systemJSConfigForBundle ( bundle , bundler , location , includeBundles ) )
88+ . filter ( bundle => bundle . name !== configBundleName )
89+ . reduce ( ( config , bundle ) => bundle . addBundleConfig ( config ) , { map : { "text" : "text" } } ) ;
90+
91+ return config ;
8192} ;
8293
8394function shouldIncludeBundleMetadata ( bundles , loaderOptions ) {
@@ -96,3 +107,23 @@ function shouldIncludeBundleMetadata(bundles, loaderOptions) {
96107
97108 return setting === true ;
98109}
110+
111+ function systemJSConfigForBundle ( bundle , bundler , location , includeBundles ) {
112+ const buildOptions = bundler . interpretBuildOptions ( bundle . config . options , bundler . buildOptions ) ;
113+ const mapTarget = location + '/' + bundle . moduleId + ( buildOptions . rev && bundle . hash ? '-' + bundle . hash : '' ) + path . extname ( bundle . config . name ) ;
114+ const moduleId = bundle . moduleId ;
115+ const bundledModuleIds = bundle . getBundledModuleIds ( ) ;
116+
117+ return {
118+ name : bundle . config . name ,
119+ addBundleConfig : function ( config ) {
120+ config . map [ moduleId ] = mapTarget ;
121+ if ( includeBundles ) {
122+ config . bundles = ( config . bundles || { } ) ;
123+ config . bundles [ moduleId ] = bundledModuleIds ;
124+ }
125+
126+ return config ;
127+ }
128+ } ;
129+ }
0 commit comments