5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { RawSourceMap , SourceMapConsumer , SourceMapGenerator } from 'source-map' ;
8
+ import { RawSourceMap } from 'source-map' ;
9
9
import * as webpack from 'webpack' ; // tslint:disable-line:no-implicit-dependencies
10
-
10
+ import { SourceMapSource } from 'webpack-sources' ;
11
11
const loaderUtils = require ( 'loader-utils' ) ;
12
12
13
13
import { buildOptimizer } from './build-optimizer' ;
@@ -53,15 +53,11 @@ export default function buildOptimizerLoader(
53
53
54
54
const options : BuildOptimizerLoaderOptions = loaderUtils . getOptions ( this ) || { } ;
55
55
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
-
60
56
const boOutput = buildOptimizer ( {
61
57
content,
62
58
originalFilePath : this . resourcePath ,
63
- inputFilePath,
64
- outputFilePath,
59
+ inputFilePath : this . resourcePath ,
60
+ outputFilePath : this . resourcePath ,
65
61
emitSourceMap : options . sourceMap ,
66
62
isSideEffectFree :
67
63
this . _module && this . _module . factoryMeta && this . _module . factoryMeta . sideEffectFree ,
@@ -84,28 +80,18 @@ export default function buildOptimizerLoader(
84
80
newContent = newContent . replace ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = [ ^ \r \n ] * / gm, '' ) ;
85
81
86
82
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.
90
83
// Use http://sokra.github.io/source-map-visualization/ to validate sourcemaps make sense.
91
84
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 ( ) ;
109
95
} else {
110
96
// Otherwise just return our generated sourcemap.
111
97
newSourceMap = intermediateSourceMap ;
0 commit comments