Skip to content

Instantly share code, notes, and snippets.

@newbornfrontender
Last active July 4, 2019 13:32
Show Gist options
  • Save newbornfrontender/80214080c73833a604e5a9d5edf46b2a to your computer and use it in GitHub Desktop.
Save newbornfrontender/80214080c73833a604e5a9d5edf46b2a to your computer and use it in GitHub Desktop.
my simple rollup-plugin-postcss (updated)
import { createFilter } from 'rollup-pluginutils';
import { writeFile } from 'fs';
import postcssrc from 'postcss-load-config';
import postcss from 'postcss';
export default (options = {}) => {
if (!options.include) options.include = '**/*.css';
const filter = createFilter(options.include, options.exclude);
return {
name: 'rollup-plugin-postcss',
async transform(source, id) {
if (!filter(id)) return;
const filename = id.split('\\').pop().split('.').shift();
const { plugins, options } = await postcssrc();
const { css } = await postcss(plugins).process(source, { ...options, from: id, to: `public/${filename}.css` });
writeFile(`public/${filename}.css`, css, () => true);
return {
code: '',
map: null,
};
},
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment