UNPKG

ng-packagr

Version:

Compile and package a TypeScript library to Angular Package Format

44 lines 2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.minifyJsFile = void 0; const terser_1 = require("terser"); const fs_extra_1 = require("fs-extra"); const path_1 = require("path"); const log_1 = require("../utils/log"); function minifyJsFile(inputPath, outputPath) { return __awaiter(this, void 0, void 0, function* () { log_1.debug(`minifyJsFile: ${inputPath}`); const sourcemapOut = `${outputPath}.map`; const [inputFileBuffer, inputSourceMapBuffer] = yield Promise.all([ fs_extra_1.readFile(inputPath), fs_extra_1.readFile(`${inputPath}.map`), ]); const result = yield terser_1.minify(inputFileBuffer.toString(), { sourceMap: { includeSources: true, content: JSON.parse(inputSourceMapBuffer.toString()), url: path_1.basename(sourcemapOut), }, parse: { ecma: 5, bare_returns: true, }, format: { comments: 'some', }, }); yield Promise.all([fs_extra_1.writeFile(outputPath, result.code), fs_extra_1.writeFile(sourcemapOut, result.map)]); return; }); } exports.minifyJsFile = minifyJsFile; //# sourceMappingURL=uglify.js.map