Last active
July 4, 2019 13:32
-
-
Save newbornfrontender/80214080c73833a604e5a9d5edf46b2a to your computer and use it in GitHub Desktop.
my simple rollup-plugin-postcss (updated)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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