Created
August 11, 2019 15:45
-
-
Save newbornfrontender/89bdf322b6e0ec286a94c90a5fad59bf to your computer and use it in GitHub Desktop.
babel postcss literal plugin
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
const deasync = require('deasync-promise'); | |
const postcss = require('postcss'); | |
const postcssrc = require('postcss-load-config'); | |
module.exports = ({ ctx }) => { | |
return { | |
visitor: { | |
TaggedTemplateExpression({ node }, { file }) { | |
if (node.tag.name !== 'css') return; | |
for ({ value } of node.quasi.quasis) { | |
const { plugins, options } = deasync(postcssrc(ctx)); | |
const { css } = deasync( | |
postcss(plugins).process(value.raw, { ...options, from: file.opts.filename }), | |
); | |
value.raw = css; | |
} | |
}, | |
}, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment