New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to use e.g. parse
and walk
without requiring entire library
#47
Comments
Hi, @Rich-Harris! |
- standalone entry points for parser, walker, generator and convertor (i.e. `require('css-tree/lib/parser')`) - replace `syntax#syntax` -> `syntax#grammar`
Just released v1.0.0-alpha22 let parse = require('css-tree/lib/parser'); // function
let walkers = require('css-tree/lib/walker'); // .all(), .allUp() etc
let generator = require('css-tree/lib/generator'); // .translate() etc
// all requires refer to folders, i.e. require('css-tree/lib/parser/index.js') is the full path to module I believe this is what you've requested. One tip: You can use let toPlainObject = require('css-tree/lib/convertor').toPlainObject;
let ast = toPlainObject(parse(css)); Or just add a "conversion" on AST tidy up: if (node.children) {
node.children = node.children.toArray();
} Btw, parser supports tolerant mode now. Maybe it would be helpful too. |
Thanks so much @lahmatiy! 🎉 |
Hi — big fan of css-tree, I tried a lot of different CSS parsers to use with Svelte and this one was by far the best, in terms of the AST format and ease of use.
This is a follow-up to sveltejs/svelte#408. To recap: for various reasons, we bundle our dependencies, and until recently (up to 1.0.0-alpha16) we were able to selectively import
parse
andwalk
like so;As of 1.0.0-alpha17 that no longer seems to be possible — we have to import the whole of css-tree. The result is that our bundle size balloons in size, from 417kb (of which 103kb was css-tree) to 770kb.
We were wondering therefore if this is a use case you might consider supporting? Or does the new extensible architecture make that very difficult?
Thank you!
cc @Conduitry
The text was updated successfully, but these errors were encountered: