-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf03d14
commit d773102
Showing
2 changed files
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import {writeFileSync} from 'fs'; | ||
import {basename} from 'path'; | ||
|
||
// There are no type definitions available for these imports. | ||
const uglify = require('uglify-js'); | ||
|
||
/** Minifies a JavaScript file by using UglifyJS2. Also writes sourcemaps to the output. */ | ||
export function uglifyJsFile(inputPath: string, outputPath: string) { | ||
const sourcemapOut = `${outputPath}.map`; | ||
const sourceMapPath = `${outputPath}.map`; | ||
|
||
const result = uglify.minify(inputPath, { | ||
outSourceMap: sourcemapOut, | ||
inSourceMap: `${inputPath}.map`, | ||
outSourceMap: basename(sourceMapPath), | ||
output: { | ||
comments: 'some' | ||
} | ||
}); | ||
|
||
writeFileSync(outputPath, result.code); | ||
writeFileSync(sourcemapOut, result.map); | ||
writeFileSync(sourceMapPath, result.map); | ||
} |