-
Notifications
You must be signed in to change notification settings - Fork 3
/
azaleaXML.js
29 lines (27 loc) · 966 Bytes
/
azaleaXML.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var Transform = require('stream').Transform;
const terser = require('terser');
module.exports = function() {
// Monkey patch Transform or create your own subclass,
// implementing `_transform()` and optionally `_flush()`
var transformStream = new Transform({objectMode: true});
/**
* @param {Buffer|string} file
* @param {string=} encoding - ignored if file contains a Buffer
* @param {function(Error, object)} callback - Call this function (optionally with an
* error argument and data) when you are done processing the supplied chunk.
*/
transformStream._transform = function(file, encoding, callback) {
var error = null;
file.contents = Buffer.from(terser.minify_sync(file.contents.toString(), {
compress: true,
ecma: 2020,
module: true,
format: {
comments: false
},
"toplevel": true,
}).code);
callback(error, file);
};
return transformStream;
};