55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- import { RawSourceMap , SourceMapConsumer , SourceMapGenerator } from 'source-map' ;
8+ import { RawSourceMap } from 'source-map' ;
99import * as webpack from 'webpack' ; // tslint:disable-line:no-implicit-dependencies
10-
10+ import { SourceMapSource } from 'webpack-sources' ;
1111const loaderUtils = require ( 'loader-utils' ) ;
1212
1313import { buildOptimizer } from './build-optimizer' ;
@@ -53,15 +53,11 @@ export default function buildOptimizerLoader(
5353
5454 const options : BuildOptimizerLoaderOptions = loaderUtils . getOptions ( this ) || { } ;
5555
56- // Make up names of the intermediate files so we can chain the sourcemaps.
57- const inputFilePath = this . resourcePath + '.pre-build-optimizer.js' ;
58- const outputFilePath = this . resourcePath + '.post-build-optimizer.js' ;
59-
6056 const boOutput = buildOptimizer ( {
6157 content,
6258 originalFilePath : this . resourcePath ,
63- inputFilePath,
64- outputFilePath,
59+ inputFilePath : this . resourcePath ,
60+ outputFilePath : this . resourcePath ,
6561 emitSourceMap : options . sourceMap ,
6662 isSideEffectFree :
6763 this . _module && this . _module . factoryMeta && this . _module . factoryMeta . sideEffectFree ,
@@ -84,28 +80,18 @@ export default function buildOptimizerLoader(
8480 newContent = newContent . replace ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = [ ^ \r \n ] * / gm, '' ) ;
8581
8682 if ( previousSourceMap ) {
87- // If there's a previous sourcemap, we have to chain them.
88- // See https://github.com/mozilla/source-map/issues/216#issuecomment-150839869 for a simple
89- // source map chaining example.
9083 // Use http://sokra.github.io/source-map-visualization/ to validate sourcemaps make sense.
9184
92- // Force the previous sourcemap to use the filename we made up for it.
93- // In order for source maps to be chained, the consumed source map `file` needs to be in the
94- // consumers source map `sources` array.
95- previousSourceMap . file = inputFilePath ;
96-
97- // Chain the sourcemaps.
98- SourceMapConsumer . with ( intermediateSourceMap , null , intermediate => {
99- return SourceMapConsumer . with ( previousSourceMap , null , previous => {
100- const generator = SourceMapGenerator . fromSourceMap ( intermediate ) ;
101- generator . applySourceMap ( previous ) ;
102-
103- return generator . toJSON ( ) ;
104- } ) ;
105- // tslint:disable-next-line: no-any
106- } ) . then ( map => callback ( null , newContent , map as any ) , error => callback ( error ) ) ;
107-
108- return ;
85+ // The last argument is not yet in the typings
86+ // tslint:disable-next-line: no-any
87+ newSourceMap = new ( SourceMapSource as any ) (
88+ newContent ,
89+ this . resourcePath ,
90+ intermediateSourceMap ,
91+ content ,
92+ previousSourceMap ,
93+ true ,
94+ ) . map ( ) ;
10995 } else {
11096 // Otherwise just return our generated sourcemap.
11197 newSourceMap = intermediateSourceMap ;
0 commit comments