Philipp Partosch 46a936d7de added all files to project | 2 years ago | |
---|---|---|
.. | ||
CHANGELOG.md | 2 years ago | |
LICENSE | 2 years ago | |
README.md | 2 years ago | |
camel-case.js | 2 years ago | |
extract.js | 2 years ago | |
get-template.js | 2 years ago | |
index.js | 2 years ago | |
literal.js | 2 years ago | |
object-parse.js | 2 years ago | |
object-parser.js | 2 years ago | |
object-stringifier.js | 2 years ago | |
object-stringify.js | 2 years ago | |
object-syntax.js | 2 years ago | |
object.js | 2 years ago | |
package.json | 2 years ago | |
template-parse.js | 2 years ago | |
template-parser-helper.js | 2 years ago | |
template-parser.js | 2 years ago | |
template-safe-parse.js | 2 years ago | |
template-safe-parser.js | 2 years ago | |
template-stringifier.js | 2 years ago | |
template-stringify.js | 2 years ago | |
template-tokenize.js | 2 years ago | |
un-camel-case.js | 2 years ago |
<img align=“right” width=“95” height=“95”
title="Philosopher’s stone, logo of PostCSS"
src="https://api.postcss.org/logo.svg">
PostCSS syntax for parsing CSS in JS literals:
First thing’s first, install the module:
npm install postcss-syntax @stylelint/postcss-css-in-js --save-dev
const postcss = require("postcss");
const stylelint = require("stylelint");
const syntax = require("postcss-syntax");
postcss([stylelint({ fix: true })])
.process(source, { syntax: syntax })
.then(function (result) {
// An alias for the result.css property. Use it with syntaxes that generate non-CSS output.
result.content;
});
input:
import glm from "glamorous";
const Component1 = glm.a({
flexDirectionn: "row",
display: "inline-block",
color: "#fff"
});
output:
import glm from "glamorous";
const Component1 = glm.a({
color: "#fff",
display: "inline-block",
flexDirectionn: "row"
});
Add support for more css-in-js
package:
const syntax = require("postcss-syntax")({
"i-css": (index, namespace) => namespace[index + 1] === "addStyles",
"styled-components": true
});
See: postcss-syntax
The main use case of this plugin is to apply PostCSS transformations to CSS code in template literals & styles as object literals.