How to use @node-minify/utils - 10 common examples

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 / core / src / setup.js View on Github external
const setup = inputSettings => {
  let settings = Object.assign(utils.clone(defaultSettings), inputSettings);

  // In memory
  if (settings.content) {
    checkMandatoriesMemoryContent(inputSettings);
    return settings;
  }

  checkMandatories(inputSettings);

  settings = Object.assign(settings, wildcards(settings.input, settings.publicFolder));
  settings = Object.assign(
    settings,
    checkOutput(settings.input, settings.output, settings.publicFolder, settings.replaceInPlace)
  );
  settings = Object.assign(settings, setPublicFolder(settings.input, settings.publicFolder));
github srod / node-minify / packages / core / src / setup.js View on Github external
const checkOutput = (input, output, publicFolder, replaceInPlace) => {
  let reg = new RegExp('\\$1');
  if (reg.test(output)) {
    if (Array.isArray(input)) {
      const outputMin = input.map(file =>
        utils.setFileNameMin(file, output, replaceInPlace ? null : publicFolder, replaceInPlace)
      );
      return { output: outputMin };
    } else {
      return { output: utils.setFileNameMin(input, output, replaceInPlace ? null : publicFolder, replaceInPlace) };
    }
  }
};
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;
};