Skip to content

gucong3000/postcss-jsx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0f5ca93 · Dec 30, 2019

History

54 Commits
Dec 30, 2019
Apr 27, 2018
May 8, 2018
Jun 2, 2019
May 8, 2018
Apr 27, 2018
Dec 29, 2018
Sep 18, 2018
Dec 30, 2019
Dec 26, 2018
Jun 19, 2018
Dec 26, 2018
Dec 26, 2018
Dec 29, 2018
Dec 30, 2019
May 4, 2018
Dec 26, 2018
Jul 27, 2018
Jul 29, 2019
Dec 29, 2018
Jun 2, 2019
Dec 28, 2018
Dec 29, 2018
Dec 28, 2018
Dec 28, 2018
Dec 28, 2018
Dec 29, 2018
Jul 29, 2019

Repository files navigation

PostCSS JSX Syntax

NPM version Travis Travis Codecov David

PostCSS syntax for parsing CSS in JS literals:

Getting Started

First thing's first, install the module:

npm install postcss-syntax postcss-jsx --save-dev

Use Cases

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',
});

Advanced Use Cases

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

Style Transformations

The main use case of this plugin is to apply PostCSS transformations to CSS code in template literals & styles as object literals.