# postcss-syntax

> Automatically switch PostCSS syntax by file extensions

Latest version **0.36.2** (published 2019-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-syntax
pnpm add postcss-syntax
yarn add postcss-syntax
bun add postcss-syntax
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.36.2 |
| Published | 2019-01-03 |
| First published | 2018-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 44 |
| Author | gucong |
| Maintainers | ai, gucong |
| Keywords | postcss, syntax, switch, extension |

## Links

- npm: https://www.npmjs.com/package/postcss-syntax
- Repository: https://github.com/gucong3000/postcss-syntax
- Homepage: https://github.com/gucong3000/postcss-syntax#readme
- Issues: https://github.com/gucong3000/postcss-syntax/issues
- npm.io page: https://npm.io/package/postcss-syntax

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 0.36.2 (latest) — 2019-01-03
- 0.36.0 — 2019-01-02
- 0.34.0 — 2018-09-18
- 0.33.0 — 2018-08-15
- 0.32.0 — 2018-07-27
- 0.31.0 — 2018-06-29
- 0.30.0 — 2018-06-20
- 0.28.0 — 2018-06-11
- 0.27.0 — 2018-06-07
- 0.26.1 — 2018-05-28
- 0.26.0 — 2018-05-28
- 0.25.0 — 2018-05-25
- 0.24.0 — 2018-05-24
- 0.9.1 — 2018-05-18
- 0.10.0 — 2018-05-18
- … 10 more at https://npm.io/package/postcss-syntax/versions

## README

PostCSS Syntax
====

[![NPM version](https://img.shields.io/npm/v/postcss-syntax.svg?style=flat-square)](https://www.npmjs.com/package/postcss-syntax)
[![Travis](https://img.shields.io/travis/gucong3000/postcss-syntax.svg)](https://travis-ci.org/gucong3000/postcss-syntax)
[![Travis](https://img.shields.io/travis/gucong3000/postcss-syntaxes.svg?label=integration)](https://travis-ci.org/gucong3000/postcss-syntaxes)
[![Codecov](https://img.shields.io/codecov/c/github/gucong3000/postcss-syntax.svg)](https://codecov.io/gh/gucong3000/postcss-syntax)
[![David](https://img.shields.io/david/dev/gucong3000/postcss-syntax.svg)](https://david-dm.org/gucong3000/postcss-syntax?type=dev)

<img align="right" width="95" height="95"
	title="Philosopher’s stone, logo of PostCSS"
	src="http://postcss.github.io/postcss/logo.svg">

postcss-syntax can automatically switch the required [PostCSS](https://github.com/postcss/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:

- SCSS: [postcss-scss](https://github.com/postcss/postcss-scss)
- SASS: [postcss-sass](https://github.com/aleshaoleg/postcss-sass)
- LESS: [postcss-less](https://github.com/shellscape/postcss-less)
- SugarSS: [sugarss](https://github.com/postcss/sugarss)

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

- CSS-in-JS: [postcss-jsx](https://github.com/gucong3000/postcss-jsx)
- HTML (and HTML-like): [postcss-html](https://github.com/gucong3000/postcss-html)
- Markdown: [postcss-markdown](https://github.com/gucong3000/postcss-markdown)

## Use Cases

```js
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: /\.(?:m?[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
});
```

---
_Source: https://npm.io/package/postcss-syntax · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
