@h4ad/node-modules-packer
Version:
<h1 align="center"> 🚀 Node Modules Packer </h1>
27 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UglifyJsTransformer = void 0;
const stream_1 = require("stream");
const terser_1 = require("terser");
class UglifyJsTransformer extends stream_1.Transform {
constructor(filePath, uglifyOptions = {}) {
super();
this.filePath = filePath;
this.uglifyOptions = uglifyOptions;
this.chunks = 0;
}
async _transform(chunk, encoding, callback) {
if (this.chunks > 0) {
return callback(new Error('This transformer should not be called more than once. Check if you use MemoryStream before using UglifyJsTransformer'));
}
console.log(`${this.filePath}:${chunk.byteLength}`);
const code = chunk.toString('utf-8');
const result = await (0, terser_1.minify)(code, this.uglifyOptions).catch(() => null);
const data = !result || !result.code ? chunk : Buffer.from(result.code, 'utf-8');
this.chunks++;
this.push(data);
callback();
}
}
exports.UglifyJsTransformer = UglifyJsTransformer;
//# sourceMappingURL=uglify-js.transformer.js.map