@@ -14,6 +14,8 @@ interface Platform {
14
14
const loaderUtils = require ( 'loader-utils' ) ;
15
15
const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
16
16
17
+ const sourceMappingUrlRe = / ^ \/ \/ # s o u r c e M a p p i n g U R L = [ ^ \r \n ] * / gm;
18
+
17
19
// This is a map of changes which need to be made
18
20
const changeMap : { [ key : string ] : Platform } = {
19
21
platformBrowserDynamic : {
@@ -544,19 +546,30 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
544
546
. then ( ( ) => {
545
547
timeEnd ( timeLabel + '.ngcLoader.AngularCompilerPlugin' ) ;
546
548
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
+
547
560
if ( plugin . failedCompilation ) {
548
561
// Return an empty string if there is no result to prevent extra loader errors.
549
562
// Plugin errors were already pushed to the compilation errors.
550
563
timeEnd ( timeLabel ) ;
551
564
cb ( null , result . outputText || '' , result . sourceMap ) ;
552
565
} else {
553
566
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 ) ;
560
573
} ) ;
561
574
} else if ( plugin instanceof AotPlugin ) {
562
575
time ( timeLabel + '.ngcLoader.AotPlugin' ) ;
@@ -686,7 +699,7 @@ export function ngcLoader(this: LoaderContext & { _compilation: any }, source: s
686
699
687
700
const result = refactor . transpile ( compilerOptions ) ;
688
701
// 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 , '' ) ;
690
703
timeEnd ( timeLabel ) ;
691
704
cb ( null , result . outputText , result . sourceMap ) ;
692
705
}
0 commit comments