====
PostCSS auto syntax switch tool
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 the corresponding module.
- SCSS: PostCSS-SCSS
- SASS: PostCSS-SASS
- LESS: PostCSS-LESS
- SugarSS: SugarSS
const postcss = require('postcss');
const syntax = require('postcss-syntax')({
processors: [
{
test: /\.(?:[sx]?html?|[sx]ht|vue|ux|php)$/i,
split: 'html',
},
{
test: /\.(?:markdown|md)$/i,
split: 'markdown',
},
{
test: /\.(?:m?[jt]sx?|es\d*|pac)$/i,
split: 'styled',
},
],
css: postcss,
sass: require('postcss-sass')
scss: require('postcss-scss')
less: require('postcss-less')
sugarss: require('sugarss')
});
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
});