How to use the clean-css function in clean-css

To help you get started, we’ve selected a few clean-css 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 WeAreGenki / minna-ui / utils / rollup-plugin-emit-css / src / index.ts View on Github external
const processCss = (css: string, id: string): void => {
        if ((!css || !/\S/.test(css)) && !emitEmpty) {
          if (debug) this.warn('CSS empty, not emitting file');
          return;
        }

        if (optimize) {
          const cleancss = new CleanCSS({
            sourceMap: false, // TODO: Add source map support
            ...(typeof optimize === 'object' ? optimize : {}),
          });

          const result = cleancss.minify(css);

          for (const err of result.warnings) this.warn(err);
          for (const err of result.errors) this.error(err);

          // eslint-disable-next-line no-param-reassign
          css = result.styles;
        }

        const name = id.replace(extname(id), '');

        this.emitAsset(`${name}.css`, css);
github nytimes / kyt / src / server / index.js View on Github external
match({ routes, history }, (error, redirectLocation, renderProps) => {
        if (error) {
          // response.status(500).send(error.message);
        } else if (redirectLocation) {
          // response.redirect(302, `${redirectLocation.pathname}${redirectLocation.search}`);
        } else if (renderProps) {
          response(template({
            root: renderToString(),
            css: new cleancss().minify(jss.sheets.toString()).styles,
            jsBundle: clientAssets.main.js
          }));
        } else {
          // response.status(404).send('Not found');
        }
      });
    }
github revivek / oy / src / utils / Renderer.js View on Github external
const renderTemplate = (element, options, generateCustomTemplate) => {
  const bodyContent = ReactDOMServer.renderToStaticMarkup(element);
  const minifiedHeadCSS = new CleanCSS().minify(options.headCSS || '').styles;
  options = objectAssign({}, {
    lang: sanitizer.escape(options.lang),
    dir: sanitizer.escape(options.dir),
    title: sanitizer.escape(options.title),
    previewText: sanitizer.escape(options.previewText),
    headCSS: CSS.raiseOnUnsafeCSS(minifiedHeadCSS, 'headCSS'),
    bgColor: sanitizer.escape(options.bgColor)
  }, {bodyContent: bodyContent});
  return generateCustomTemplate ? (
    generateCustomTemplate(options)
  ) : HTML4.generateDefaultTemplate(options);
};
github ArkEcosystem / desktop-wallet / src / renderer / App.vue View on Github external
applyPluginTheme (themeName) {
      if (themeName && this.pluginThemes) {
        const theme = this.pluginThemes[themeName]
        if (theme) {
          const $style = document.querySelector('style[name=plugins]')
          const input = fs.readFileSync(theme.cssPath)
          const output = new CleanCss().minify(input)
          $style.innerHTML = output.styles
        }
      }
    }
  }
github Akryum / vue-virtual-scroller / build / rollup.config.base.js View on Github external
css (style) {
        const file = require.resolve('vue-resize/dist/vue-resize.css')
        style += fs.readFileSync(file, { encoding: 'utf8' })
        fs.writeFileSync('dist/vue-virtual-scroller.css', new CleanCSS().minify(style).styles)
      },
    }),
github purifycss / purifycss / lib / purifycss.es.js View on Github external
var minify = function minify(cssSource, options) {
    return new CleanCss(options).minify(cssSource).styles;
};
github thealjey / webcompiler / lib / compiler.js View on Github external
function minifyCSS(inPath: string, outPath: string, callback: Function, result: Object) {
  var sourceMappingURL = result.css.match(/\n.+$/)[0];

  result = new CleanCSS({
    keepSpecialComments: 0,
    roundingPrecision: -1,
    sourceMap: JSON.stringify(result.map),
    sourceMapInlineSources: true
  }).minify(result.css);
  zlib.gzip(result.styles + sourceMappingURL, function jsGzipHandler(e, code) {
    if (e) {
      return consoleError(e);
    }
    fs.writeFile(outPath, code, function jsWriteCompressedScriptHandler(styleErr) {
      if (styleErr) {
        return consoleError(styleErr);
      }
      fs.writeFile(outPath + '.map', result.sourceMap, function cssWriteMapHandler(mapErr) {
        if (mapErr) {
          return consoleError(mapErr);
github thealjey / webcompiler / lib / cssMin.js View on Github external
export default function cssMin(data: Object): Object {
  const sourceMappingURL = data.code.match(/\n.+$/)[0],
      result = new CleanCSS({
        keepSpecialComments: 0,
        roundingPrecision,
        sourceMap: data.map,
        sourceMapInlineSources: true
      }).minify(data.code);

  return {code: result.styles + sourceMappingURL, map: result.sourceMap};
}
github martinandert / react-inline / src / buildCSS.js View on Github external
if (css.length === 0) {
    return null;
  }

  const vp = options.vendorPrefixes;

  if (vp) {
    if (typeof vp === 'object') {
      css = postcss([autoprefixer(vp)]).process(css).css;
    } else {
      css = postcss([autoprefixer]).process(css).css;
    }
  }

  if (options.minify) {
    css = new CleanCSS().minify(css).styles;
  }

  return css;
}
github frappe / charts / rollup.config.js View on Github external
.then(result => {
			let options = {
				level: {
					1: {
						removeQuotes: false,
					}
				}
			}
			let output = new CleanCSS(options).minify(result.css);
			let res = JSON.stringify(output.styles).replace(/"/g, "'");
			let js = `export const CSSTEXT = "${res.slice(1, -1)}";`;
            fs.writeFile('src/css/chartsCss.js', js);
        });
});

clean-css

A well-tested CSS minifier

MIT
Latest version published 5 months ago

Package Health Score

86 / 100
Full package analysis