SHARE
TWEET

Untitled

a guest Jul 15th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { createFilter } from 'rollup-pluginutils';
  2. import { writeFile } from 'fs';
  3. import postcssrc from 'postcss-load-config';
  4. import postcss from 'postcss';
  5.  
  6. export default (options = {}) => {
  7.   if (!options.include) options.include = '**/*.css';
  8.  
  9.   const filter = createFilter(options.include, options.exclude);
  10.  
  11.   return {
  12.     name: 'rollup-plugin-postcss',
  13.  
  14.     async transform(source, id) {
  15.       if (!filter(id)) return;
  16.  
  17.       const filename = id.split('\\').pop().split('.').shift();
  18.       const { plugins, options } = await postcssrc();
  19.       const { css } = await postcss(plugins).process(source, { ...options, from: id, to: `public/${filename}.css` });
  20.  
  21.       writeFile(`public/${filename}.css`, css, () => true);
  22.  
  23.       return {
  24.         code: '',
  25.         map: null,
  26.       };
  27.     },
  28.   };
  29. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top