Giter Club home page Giter Club logo

postcss-syntax's Introduction

PostCSS Syntax

NPM version Travis Travis Codecov David

postcss-syntax can automatically switch the required PostCSS syntax by file extension/source

Getting Started

First thing's first, install the module:

npm install postcss-syntax --save-dev

If you want support SCSS/SASS/LESS/SugarSS syntax, you need to install these module:

If you want support HTML (and HTML-like)/Markdown/CSS-in-JS file format, you need to install these module:

Use Cases

const postcss = require('postcss');
const syntax = require('postcss-syntax')({
	rules: [
		{
			test: /\.(?:[sx]?html?|[sx]ht|vue|ux|php)$/i,
			extract: 'html',
		},
		{
			test: /\.(?:markdown|md)$/i,
			extract: 'markdown',
		},
		{
			test: /\.(?:[cm]?[jt]sx?|es\d*|pac)$/i,
			extract: 'jsx',
		},
		{
			// custom language for file extension
			test: /\.postcss$/i,
			lang: 'scss'
		},
		{
			// custom language for file extension
			test: /\.customcss$/i,
			lang: 'custom'
		},
	],

	// custom parser for CSS (using `postcss-safe-parser`)
	css: 'postcss-safe-parser',
	// custom parser for SASS (PostCSS-compatible syntax.)
	sass: require('postcss-sass'),
	// custom parser for SCSS (by module name)
	scss: 'postcss-scss',
	// custom parser for LESS (by module path)
	less: './node_modules/postcss-less',
	// custom parser for SugarSS
	sugarss: require('sugarss'),
	// custom parser for custom language
	custom: require('postcss-custom-syntax'),

});
postcss(plugins).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
});

postcss-syntax's People

Contributors

gucong3000 avatar bpscott avatar kaisermann avatar jvega avatar shinnn avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.