postcss-media-query-parser icon indicating copy to clipboard operation
postcss-media-query-parser copied to clipboard

feat: handle string url in `@import` directive

Open alexander-akait opened this issue 7 years ago • 14 comments

handle @import "common.css" screen, projection

@dryoma Also can you invite me in repo with PR and publish right? Need for stylelint and prettier fixes, thanks!

alexander-akait avatar Jan 19 '18 13:01 alexander-akait

@evilebottnawi - I'm very new to postcss but have a need for this plugin. I'd help with maintenance if you chose to fork it, gonna fork it myself to make it simpler for cjs

const parser = require('postcss-media-query-parser').default
                                                     ^
                                      'default' should be unnecessary

olsonpm avatar Mar 16 '18 18:03 olsonpm

I ended up just creating https://github.com/olsonpm/postcss-create-mq-ast instead. The csstree parser will eventually be merged into postcss and it parses media queries, so it's an interim solution. It also made life easy and standard as opposed to a home-grown ast structure.

olsonpm avatar Mar 21 '18 07:03 olsonpm

@olsonpm will be awesome create plugin what handle any at-rules

alexander-akait avatar Mar 21 '18 08:03 alexander-akait

you mean attach an csstree ast to all at-rule nodes?

olsonpm avatar Mar 21 '18 08:03 olsonpm

@olsonpm yep :+1:

alexander-akait avatar Mar 21 '18 09:03 alexander-akait

good idea. i only focused on the media query because that's all i needed. i'll look into it tomorrow

olsonpm avatar Mar 21 '18 09:03 olsonpm

I see a couple options:

  1. Provide the full csstree ast for each at-rule.

    • Pro: in case of font-face and likely others, it provides detail missing in postcss ast
    • Con: a lot of duplicate information, more cluttered/confusing ast
  2. Provide the prelude csstree ast (e.g. ast of postcss "params" property

    • Pro: simpler, no duplicate info
    • Con: leaves other missing ast details up to other plugins to handle

for reference, here's a gist of browser supported css at-rules I parsed using both libraries

I'd personally vote for #2, but I'm new to PostCSS so I wouldn't know what people would find more useful. I also don't even know that postcss plugin makers would be comfortable working between two ast structures.

olsonpm avatar Mar 21 '18 17:03 olsonpm

@olsonpm csstree is good tool, but he don't support comments and it is very bad for tools such as stylelint and prettier and maybe for other tools :disappointed:

alexander-akait avatar Mar 21 '18 17:03 alexander-akait

right - they will change that later. I'm only using it to give us the AST to what they term as the "prelude" statements. I'm also not removing any postcss ast nodes, only attaching additional information.

Whether they support comments shouldn't matter

olsonpm avatar Mar 21 '18 17:03 olsonpm

@olsonpm they promise support for comments around 1-2 years, this is unacceptable :smile: PostCSS parses (value/selector) already support a lot of features. Also PostCSS is standard tool in DX. I think better create new parser (aka postcss-at-rule-parser).

alexander-akait avatar Mar 21 '18 18:03 alexander-akait

that doesn't change the fact that the direction is for them to bring the csstree parser into postcss. I don't think they planned on creating a whole new parser.

olsonpm avatar Mar 21 '18 18:03 olsonpm

Ah i see what you mean - that the community would benefit from a module which parses at-rules just like value/selector. You're right, but that's more work then I'm willing to put in for something I don't personally need.

olsonpm avatar Mar 21 '18 18:03 olsonpm

@alexander-akait @olsonpm Three years later, has the support for comments in css-tree been improved?

yisibl avatar Jul 15 '22 11:07 yisibl

not sure, but gonna unsubscribe from this thread. i forget what my usecase for this was

olsonpm avatar Jul 15 '22 13:07 olsonpm