@@ -31,6 +31,24 @@ function bundle(entryPoints, config, callback) {
3131 var loader = loaderModule . exports ;
3232 config . isBuild = true ;
3333 loader . config ( config ) ;
34+ loader ( [ 'require' ] , function ( localRequire ) {
35+ var resolvePath = function ( path ) {
36+ var r = localRequire . toUrl ( path ) ;
37+ if ( ! / \. j s / . test ( r ) ) {
38+ return r + '.js' ;
39+ }
40+ return r ;
41+ } ;
42+ for ( var moduleId in entryPointsMap ) {
43+ var entryPoint = entryPointsMap [ moduleId ] ;
44+ if ( entryPoint . append ) {
45+ entryPoint . append = entryPoint . append . map ( resolvePath ) ;
46+ }
47+ if ( entryPoint . prepend ) {
48+ entryPoint . prepend = entryPoint . prepend . map ( resolvePath ) ;
49+ }
50+ }
51+ } ) ;
3452 loader ( Object . keys ( allMentionedModulesMap ) , function ( ) {
3553 var modules = loader . getBuildInfo ( ) ;
3654 var partialResult = emitEntryPoints ( modules , entryPointsMap ) ;
@@ -74,7 +92,7 @@ function emitEntryPoints(modules, entryPoints) {
7492 return allDependencies [ module ] ;
7593 } ) ;
7694 bundleData . bundles [ moduleToBundle ] = includedModules ;
77- var res = emitEntryPoint ( modulesMap , modulesGraph , moduleToBundle , includedModules ) ;
95+ var res = emitEntryPoint ( modulesMap , modulesGraph , moduleToBundle , includedModules , info . prepend , info . append , info . dest ) ;
7896 result = result . concat ( res . files ) ;
7997 for ( var pluginName in res . usedPlugins ) {
8098 usedPlugins [ pluginName ] = usedPlugins [ pluginName ] || res . usedPlugins [ pluginName ] ;
@@ -235,10 +253,13 @@ function removeDuplicateTSBoilerplate(destFiles) {
235253 } ) ;
236254 return destFiles ;
237255}
238- function emitEntryPoint ( modulesMap , deps , entryPoint , includedModules ) {
256+ function emitEntryPoint ( modulesMap , deps , entryPoint , includedModules , prepend , append , dest ) {
257+ if ( ! dest ) {
258+ dest = entryPoint + '.js' ;
259+ }
239260 var mainResult = {
240261 sources : [ ] ,
241- dest : entryPoint + '.js'
262+ dest : dest
242263 } , results = [ mainResult ] ;
243264 var usedPlugins = { } ;
244265 var getLoaderPlugin = function ( pluginName ) {
@@ -286,6 +307,16 @@ function emitEntryPoint(modulesMap, deps, entryPoint, includedModules) {
286307 plugin . writeFile ( pluginName , entryPoint , req , write , { } ) ;
287308 }
288309 } ) ;
310+ var toIFile = function ( path ) {
311+ var contents = readFileAndRemoveBOM ( path ) ;
312+ return {
313+ path : path ,
314+ contents : contents
315+ } ;
316+ } ;
317+ var toPrepend = ( prepend || [ ] ) . map ( toIFile ) ;
318+ var toAppend = ( append || [ ] ) . map ( toIFile ) ;
319+ mainResult . sources = toPrepend . concat ( mainResult . sources ) . concat ( toAppend ) ;
289320 return {
290321 files : results ,
291322 usedPlugins : usedPlugins
0 commit comments