CSScomb Core: postprocessor in 15 minsЭтот пост на русском
Want to write your own postprocessor but don’t want to spend much time?
Just fork a special template and modify it.
This summer CSScomb.js turns 1 year.
We have spent this time working on amazing project which is now easy to maintain and easy to scale.
Today I’d love to share a part of our work which will help you create your own projects.
The heart of our tool is now available as a separate module — CSScomb Core.
You can use it to write different postprocessors.
I’ve made a template repo to show you how simple it is.
Just fork it and play with code.
Parser with preprocessors support
Our tool is based on Gonzales PE.
This parser can process not only CSS, but preprocessors too: LESS, Sass and SCSS.
API to work with configs
Sometimes postprocessors need to be configured.
CSScomb has 25 settings, for example.
As a user you can write a config file to set the options you need.
And it’s easy to apply that config with CSScomb Core:
var config = require(‘path/to/config.json’); core.configure(config);
API to write and use plugins
var option = require(‘path/to/option’); core.use(option);
API to work with files
Whether you want to process a single file or a whole directory — it’s easy to get done.
We take care of syntax detection and working with file system:
core.processString(string, syntax); core.processFile(‘path/to/file.css’); core.processDirectory(‘path/to/dir’);
There is a tiny template
I’ve made to help you get started.
The postprocessor is called Flip Comb and all it does is replace comments in CSS files with
/ (╯°□°）╯︵ ┻━┻ /.
It took me 15 minutes to write those two files.
The result is pretty useless, but you can learn something from it.
Just fork the repo and play around.
When you are ready to go further, read docs for more information.