Skip to content

Instantly share code, notes, and snippets.

@newbornfrontender
Created August 11, 2019 15:45
Show Gist options
  • Save newbornfrontender/89bdf322b6e0ec286a94c90a5fad59bf to your computer and use it in GitHub Desktop.
Save newbornfrontender/89bdf322b6e0ec286a94c90a5fad59bf to your computer and use it in GitHub Desktop.
babel postcss literal plugin
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