@@ -13,6 +13,7 @@ import {
13
13
14
14
// There are no type definitions available for these imports.
15
15
const uglify = require ( 'uglify-js' ) ;
16
+ const sorcery = require ( 'sorcery' ) ;
16
17
17
18
/**
18
19
* Copies different output files into a folder structure that follows the `angular/angular`
@@ -28,8 +29,8 @@ export function composeRelease(packageName: string) {
28
29
inlinePackageMetadataFiles ( packagePath ) ;
29
30
30
31
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' ) ) ;
33
34
copyFiles ( PROJECT_ROOT , 'LICENSE' , releasePath ) ;
34
35
copyFiles ( SOURCE_ROOT , 'README.md' , releasePath ) ;
35
36
copyFiles ( sourcePath , 'package.json' , releasePath ) ;
@@ -57,13 +58,17 @@ export async function buildModuleEntry(entryFile: string, entryName = 'material'
57
58
format : 'es' ,
58
59
} ) ;
59
60
61
+ await remapSourcemap ( fesm2015File ) ;
62
+
60
63
// Downlevel FESM-2015 file to ES5.
61
64
transpileFile ( fesm2015File , fesm2014File , {
62
65
target : ScriptTarget . ES5 ,
63
66
module : ModuleKind . ES2015 ,
64
67
allowJs : true
65
68
} ) ;
66
69
70
+ await remapSourcemap ( fesm2014File ) ;
71
+
67
72
// Create UMD bundle of FESM-2014 output.
68
73
await createRollupBundle ( {
69
74
moduleName : moduleName ,
@@ -72,8 +77,31 @@ export async function buildModuleEntry(entryFile: string, entryName = 'material'
72
77
format : 'umd'
73
78
} ) ;
74
79
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 ) ;
77
105
}
78
106
79
107
function copyFiles ( fromPath : string , fileGlob : string , outDir : string ) {
0 commit comments