postcss-advanced-variables icon indicating copy to clipboard operation
postcss-advanced-variables copied to clipboard

Feature request: process mixin without inlining import

Open aoberoi opened this issue 6 years ago • 1 comments

Thanks for this awesome project!

I'm wondering if you'd be open to accepting contributions, and would be available to provide guidance, for the following new feature.

I'd like to be able to @import 'some-identifier', which contains syntax that is never emitted (specifically a @mixin declaration), and still choose not to have the target file inlined. I can currently use the disable option (or the importFilter option) to turn off inlining, but when I do, the @include cannot resolve references to mixins in the @imported files. I get an error like this:

CssSyntaxError: postcss-advanced-variables: /path/test.css:4:12: Could not resolve the mixin for "my-mixin"

Why? I'd like to centralize the definition of mixins and other declarations that have a particular concern. I also am choosing not to inline @imports because my deliverable is a library, where I feel consumers of the library should choose if and how they want the individual files bundled. My goal is to emit standard CSS that is reusable across many projects, so the @mixin/@include should be processed out of the output.

Example

Input:

/* spacing.css */
@mixin no-spacing {
  margin: 0;
  padding: 0;
}

:root {
 --other-spacing-related-var: 30px;
}

/* typography.css */
@import './spacing.css';

.my-header {
  @include no-spacing
  font-size: 20px;
  line-height: 1.6;
  font-weight: 700;
}

Output (desired) when processing typography.css:

@import './spacing.css';

.my-header {
  margin: 0;
  padding: 0;
  font-size: 20px;
  line-height: 1.6;
  font-weight: 700;
}

aoberoi avatar Dec 28 '18 01:12 aoberoi

Here is a whole other postcss plugin with a related motivation: https://github.com/dehuszar/postcss-reference. I think if we added this feature to this plugin, we'd be able to solve for many of those use cases without introducing new/unfamiliar syntax.

aoberoi avatar Dec 28 '18 01:12 aoberoi