How to use the @node-minify/utils.utils.writeFile function in @node-minify/utils

To help you get started, we’ve selected a few @node-minify/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github srod / node-minify / packages / babel-minify / src / babel-minify.js View on Github external
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;
};
github srod / node-minify / packages / uglify-es / src / uglify-es.js View on Github external
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;
};
github srod / node-minify / packages / no-compress / src / no-compress.js View on Github external
const noCompress = ({ settings, content, callback, index }) => {
  if (!settings.content) {
    utils.writeFile({ file: settings.output, content, index });
  }
  if (callback) {
    return callback(null, content);
  }
  return content;
};
github srod / node-minify / packages / cssnano / src / cssnano.js View on Github external
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;
};
github srod / node-minify / packages / crass / src / crass.js View on Github external
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;
};
github srod / node-minify / packages / csso / src / csso.js View on Github external
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;
};
github srod / node-minify / packages / uglify-js / src / uglify-js.js View on Github external
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;
};
github srod / node-minify / packages / sqwish / src / sqwish.js View on Github external
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;
};
github srod / node-minify / packages / clean-css / src / clean-css.js View on Github external
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;
};
github srod / node-minify / packages / html-minifier / src / html-minifier.js View on Github external
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;
};