@@ -13,6 +13,7 @@ import {
1313
1414// There are no type definitions available for these imports.
1515const uglify = require ( 'uglify-js' ) ;
16+ const sorcery = require ( 'sorcery' ) ;
1617
1718/**
1819 * Copies different output files into a folder structure that follows the `angular/angular`
@@ -28,8 +29,8 @@ export function composeRelease(packageName: string) {
2829 inlinePackageMetadataFiles ( packagePath ) ;
2930
3031 copyFiles ( packagePath , '**/*.+(d.ts|metadata.json)' , join ( releasePath , 'typings' ) ) ;
31- copyFiles ( DIST_BUNDLES , `${ packageName } .umd?(.min).js` , join ( releasePath , 'bundles' ) ) ;
32- copyFiles ( DIST_BUNDLES , `${ packageName } ?(.es5).js` , join ( releasePath , '@angular' ) ) ;
32+ copyFiles ( DIST_BUNDLES , `${ packageName } .umd?(.min).js?(.map) ` , join ( releasePath , 'bundles' ) ) ;
33+ copyFiles ( DIST_BUNDLES , `${ packageName } ?(.es5).js?(.map) ` , join ( releasePath , '@angular' ) ) ;
3334 copyFiles ( PROJECT_ROOT , 'LICENSE' , releasePath ) ;
3435 copyFiles ( SOURCE_ROOT , 'README.md' , releasePath ) ;
3536 copyFiles ( sourcePath , 'package.json' , releasePath ) ;
@@ -57,13 +58,17 @@ export async function buildModuleEntry(entryFile: string, entryName = 'material'
5758 format : 'es' ,
5859 } ) ;
5960
61+ await remapSourcemap ( fesm2015File ) ;
62+
6063 // Downlevel FESM-2015 file to ES5.
6164 transpileFile ( fesm2015File , fesm2014File , {
6265 target : ScriptTarget . ES5 ,
6366 module : ModuleKind . ES2015 ,
6467 allowJs : true
6568 } ) ;
6669
70+ await remapSourcemap ( fesm2014File ) ;
71+
6772 // Create UMD bundle of FESM-2014 output.
6873 await createRollupBundle ( {
6974 moduleName : moduleName ,
@@ -72,8 +77,31 @@ export async function buildModuleEntry(entryFile: string, entryName = 'material'
7277 format : 'umd'
7378 } ) ;
7479
75- // Output a minified version of the UMD bundle
76- writeFileSync ( umdMinFile , uglify . minify ( umdFile , { preserveComments : 'license' } ) . code ) ;
80+ await remapSourcemap ( umdFile ) ;
81+
82+ uglifyFile ( umdFile , umdMinFile ) ;
83+
84+ await remapSourcemap ( umdMinFile ) ;
85+ }
86+
87+ /**
88+ * Finds the original sourcemap of the file and maps it to the current file.
89+ * This is useful when multiple transformation happen (e.g TSC -> Rollup -> Uglify)
90+ **/
91+ async function remapSourcemap ( sourceFile : string ) {
92+ ( await sorcery . load ( sourceFile ) ) . write ( ) ;
93+ }
94+
95+ /** Minifies a JavaScript file using UglifyJS2. Also writes sourcemaps to the output. */
96+ function uglifyFile ( inputPath : string , outputPath : string ) {
97+ let sourcemapOut = `${ outputPath } .map` ;
98+ let result = uglify . minify ( inputPath , {
99+ preserveComments : 'license' ,
100+ outSourceMap : sourcemapOut
101+ } ) ;
102+
103+ writeFileSync ( outputPath , result . code ) ;
104+ writeFileSync ( sourcemapOut , result . map ) ;
77105}
78106
79107function copyFiles ( fromPath : string , fileGlob : string , outDir : string ) {
0 commit comments