@@ -14,6 +14,8 @@ interface Platform {
1414const loaderUtils = require ( 'loader-utils' ) ;
1515const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
1616
17+ const sourceMappingUrlRe = / ^ \/ \/ # s o u r c e M a p p i n g U R L = [ ^ \r \n ] * / gm;
18+
1719// This is a map of changes which need to be made
1820const changeMap : { [ key : string ] : Platform } = {
1921 platformBrowserDynamic : {
@@ -544,19 +546,30 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
544546 . then ( ( ) => {
545547 timeEnd ( timeLabel + '.ngcLoader.AngularCompilerPlugin' ) ;
546548 const result = plugin . getFile ( sourceFileName ) ;
549+
550+ if ( result . sourceMap ) {
551+ // Process sourcemaps for Webpack.
552+ // Remove the sourceMappingURL.
553+ result . outputText = result . outputText . replace ( sourceMappingUrlRe , '' ) ;
554+ // Set the map source to use the full path of the file.
555+ const sourceMap = JSON . parse ( result . sourceMap ) ;
556+ sourceMap . sources [ 0 ] = sourceFileName ;
557+ result . sourceMap = JSON . stringify ( sourceMap ) ;
558+ }
559+
547560 if ( plugin . failedCompilation ) {
548561 // Return an empty string if there is no result to prevent extra loader errors.
549562 // Plugin errors were already pushed to the compilation errors.
550563 timeEnd ( timeLabel ) ;
551564 cb ( null , result . outputText || '' , result . sourceMap ) ;
552565 } else {
553566 timeEnd ( timeLabel ) ;
554- cb ( null , result . outputText , result . sourceMap ) ;
555- }
556- } )
557- . catch ( err => {
558- timeEnd ( timeLabel + '.ngcLoader.AngularCompilerPlugin' ) ;
559- cb ( err ) ;
567+ cb ( null , result . outputText , result . sourceMap ) ;
568+ }
569+ } )
570+ . catch ( err => {
571+ timeEnd ( timeLabel + '.ngcLoader.AngularCompilerPlugin' ) ;
572+ cb ( err ) ;
560573 } ) ;
561574 } else if ( plugin instanceof AotPlugin ) {
562575 time ( timeLabel + '.ngcLoader.AotPlugin' ) ;
@@ -686,7 +699,7 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
686699
687700 const result = refactor . transpile ( compilerOptions ) ;
688701 // Webpack is going to take care of this.
689- result . outputText = result . outputText . replace ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = [ ^ \r \n ] * / gm , '' ) ;
702+ result . outputText = result . outputText . replace ( sourceMappingUrlRe , '' ) ;
690703 timeEnd ( timeLabel ) ;
691704 cb ( null , result . outputText , result . sourceMap ) ;
692705 }
0 commit comments