utils/build-css/index.js
async function processCss({ from, to, banner }) {
  const src = await readFile(from, 'utf8');

  const { plugins, options } = await postcssLoadConfig({
    from,
    to,
    map: { inline: false },
  });

  const sourceCss = banner + src;
  const result = await postcss(plugins).process(sourceCss, options);

  compileWarn('PostCSS', 'WARN', result.warnings());

  // minify resulting CSS
  const min = await new CleanCSS({
    level: {
      1: { all: true },
      2: { all: true },
    },
    returnPromise: true,
    sourceMap: true,
  }).minify(result.css, result.map.toString());

  compileWarn('CleanCSS', 'ERR', min.errors);
  compileWarn('CleanCSS', 'WARN', min.warnings);

  // clean-css removes the source map comment so we need to add it back in
  min.styles = `${min.styles}\n/*# sourceMappingURL=${basename(
    options.to,
  )}.map */`;

  writeFile(options.to, min.styles);
  writeFile(`${options.to}.map`, min.sourceMap.toString());

  return {
    min,
    result,
  };
}
async function processCss({ from, to, banner }) {
  const src = await readFile(from, 'utf8');

  const { plugins, options } = await postcssLoadConfig({
    from,
    to,
    map: { inline: false },
  });

  const sourceCss = banner + src;
  const result = await postcss(plugins).process(sourceCss, options);

  compileWarn('PostCSS', 'WARN', result.warnings());

  // minify resulting CSS
  const min = await new CleanCSS({
    level: {
      1: { all: true },
      2: { all: true },
    },
    returnPromise: true,
    sourceMap: true,
  }).minify(result.css, result.map.toString());

  compileWarn('CleanCSS', 'ERR', min.errors);
  compileWarn('CleanCSS', 'WARN', min.warnings);

  // clean-css removes the source map comment so we need to add it back in
  min.styles = `${min.styles}\n/*# sourceMappingURL=${basename(
    options.to,
  )}.map */`;

  writeFile(options.to, min.styles);
  writeFile(`${options.to}.map`, min.sourceMap.toString());

  return {
    min,
    result,
  };
}
async function processCss ( { from , to , banner } ) { const src = await readFile ( from , 'utf8' ) ; const { plugins , options } = await postcssLoadConfig ( { from , to , map : { inline : false } , } ) ; const sourceCss = banner + src ; const result = await postcss ( plugins ) . process ( sourceCss , options ) ; compileWarn ( 'PostCSS' , 'WARN' , result . warnings ( ) ) ; // minify resulting CSS const min = await new CleanCSS ( { level : { 1 : { all : true } , 2 : { all : true } , } , returnPromise : true , sourceMap : true , } ) . minify ( result . css , result . map . toString ( ) ) ; compileWarn ( 'CleanCSS' , 'ERR' , min . errors ) ; compileWarn ( 'CleanCSS' , 'WARN' , min . warnings ) ; // clean-css removes the source map comment so we need to add it back in min . styles = ` ${ min . styles } \n ${ basename ( options . to , ) } ` ; writeFile ( options . to , min . styles ) ; writeFile ( ` ${ options . to } ` , min . sourceMap . toString ( ) ) ; return { min , result , } ; }
Process CSS.
@param {Object} opts User defined options.
@param {string} opts.from File from.
@param {string} opts.to File to.
@param {string} opts.banner Banner to prepend to resulting code.
@returns {Promise<{min: Object, result: Object}>}
Process CSS .