Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (settings.options.babelrc) {
babelOptions = JSON.parse(utils.readFile(settings.options.babelrc));
}
if (settings.options.presets) {
const babelrcPresets = babelOptions.presets || [];
babelOptions.presets = babelrcPresets.concat(settings.options.presets);
}
if (babelOptions.presets.indexOf('minify') === -1) {
babelOptions.presets = babelOptions.presets.concat([minify]);
}
const contentMinified = transform(content, babelOptions);
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified.code, index });
}
if (callback) {
return callback(null, contentMinified.code);
}
return contentMinified.code;
};
const minifyUglifyES = ({ settings, content, callback, index }) => {
if (settings.options.sourceMap) {
content = { [settings.options.sourceMap.filename]: content };
}
const contentMinified = uglifyES.minify(content, settings.options);
if (contentMinified.error) {
if (callback) {
return callback(contentMinified.error);
}
}
if (contentMinified.map && settings.options.sourceMap) {
utils.writeFile({ file: `${settings.output}.map`, content: contentMinified.map, index });
}
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified.code, index });
}
if (callback) {
return callback(null, contentMinified.code);
}
return contentMinified.code;
};
const noCompress = ({ settings, content, callback, index }) => {
if (!settings.content) {
utils.writeFile({ file: settings.output, content, index });
}
if (callback) {
return callback(null, content);
}
return content;
};
const minifyCssnano = async ({ settings, content, callback, index }) => {
let contentMinified;
try {
contentMinified = await postcss([cssnano]).process(content, { from: undefined });
} catch (e) {
if (callback) {
return callback(e);
}
}
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified.css, index });
}
if (callback) {
return callback(null, contentMinified.css);
}
return contentMinified.css;
};
const minifyCrass = ({ settings, content, callback, index }) => {
const contentMinified = crass
.parse(content)
.optimize()
.toString();
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified, index });
}
if (callback) {
return callback(null, contentMinified);
}
return contentMinified;
};
const minifyCSSO = ({ settings, content, callback, index }) => {
const contentMinified = csso.minify(content, settings.options.restructureOff);
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified.css, index });
}
if (callback) {
return callback(null, contentMinified.css);
}
return contentMinified.css;
};
const minifyUglifyJS = ({ settings, content, callback, index }) => {
const contentMinified = uglifyJS.minify(content, settings.options);
if (contentMinified.error) {
if (callback) {
return callback(contentMinified.error);
}
}
if (contentMinified.map && settings.options.sourceMap) {
utils.writeFile({ file: settings.options.sourceMap.filename, content: contentMinified.map, index });
}
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified.code, index });
}
if (callback) {
return callback(null, contentMinified.code);
}
return contentMinified.code;
};
const minifySqwish = ({ settings, content, callback, index }) => {
const contentMinified = sqwish.minify(content, settings.options.strict);
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified, index });
}
if (callback) {
return callback(null, contentMinified);
}
return contentMinified;
};
const minifyCleanCSS = ({ settings, content, callback, index }) => {
if (settings.options.sourceMap) {
settings.options._sourceMap = settings.options.sourceMap;
settings.options.sourceMap = true;
}
const _cleanCSS = new CleanCSS(settings.options).minify(content);
const contentMinified = _cleanCSS.styles;
if (_cleanCSS.sourceMap && settings.options._sourceMap) {
utils.writeFile({ file: settings.options._sourceMap.url, content: _cleanCSS.sourceMap.toString(), index });
}
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified, index });
}
if (callback) {
return callback(null, contentMinified);
}
return contentMinified;
};
const minifyHTMLMinifier = ({ settings, content, callback, index }) => {
const options = Object.assign({}, defaultOptions, settings.options);
const contentMinified = HTMLMinifier(content, options);
if (!settings.content) {
utils.writeFile({ file: settings.output, content: contentMinified, index });
}
if (callback) {
return callback(null, contentMinified);
}
return contentMinified;
};