Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async transpileAndMinify() {
this.log.info('transpiling and uglifying');
const settings = this.$.desktop.getSettings();
const options = 'uglifyOptions' in settings ? settings.uglifyOptions : {};
const uglifyingEnabled = 'uglify' in settings && !!settings.uglify;
const preset = presetEnv({ assertVersion: () => { } }, { targets: { node: '12' } });
const { data: files } = await this.$.utils.readDir(this.$.env.paths.desktopTmp.root);
files.forEach((file) => {
if (file.endsWith('.js')) {
let { code } = transformFileSync(file, {
presets: [preset]
});
let error;
if (settings.env === 'prod' && uglifyingEnabled) {
({ code, error } = uglify.minify(code, options));
}
if (error) {
throw new Error(error);
}
fs.writeFileSync(file, code);
function getNeededPlugins(targets: BabelTargets): Array {
return presetEnv(
{assertVersion: () => true},
{targets: targets},
).plugins.filter(p => p[0]);
}