react-native-css-modules icon indicating copy to clipboard operation
react-native-css-modules copied to clipboard

Allow platform extensions in preprocessor imports

Open birkir opened this issue 7 years ago • 6 comments

Currently the import system for each supported preprocessor works independently, so we won't get the features from metro bundler built in.

It would be great to be able to do something like this:

// variables.ios.scss
$primary-color: blue;

// variables.android.scss
$primary-color: red;

// helloworld.scss
@include 'variables.scss';

.helloWorld {
  color: $primary-color;
}

Which would result in blue color for android and red color for ios.

It would be great to be able to use metros resolver for this, but second option would be to implement extension to each preprocessors resolver somehow.

Note: platform extensions work when importing from JavaScript, this issue is about within an css file.

birkir avatar Aug 02 '18 05:08 birkir

I think that we can add support for platform specific Sass/Less/Stylus imports to the transformers.

It would be great to have it supported by React Native's bundler, but at the same time it's probably much faster to do it for each transfomer.

kristerkari avatar Aug 02 '18 18:08 kristerkari

Good news! With react native 57, the metro packager has been updated with support for custom config.

We should be getting closer to hooking into the resolver!

https://github.com/facebook/metro/tree/master/packages/metro-config

birkir avatar Aug 09 '18 02:08 birkir

That's great! Looking forward to RN 57 to be released.

kristerkari avatar Aug 09 '18 05:08 kristerkari

I've been playing around with v0.57.0-rc.2 today. I'm trying to get a good understanding of the new Metro options before the final version is released.

So far I only managed to get some errors when updating to the new config, so I need to get past that to test the new config options.

kristerkari avatar Aug 24 '18 21:08 kristerkari

I started doing this by adding support for the Sass transformer: https://github.com/kristerkari/react-native-sass-transformer/pull/16

kristerkari avatar Oct 17 '18 18:10 kristerkari

Status:

  • [x] Support for Sass transformer (as of v1.3.0)
  • [ ] Support for Less transformer
  • [ ] Support for PostCSS transformer
  • [ ] Support for Stylus transformer

kristerkari avatar Oct 20 '18 19:10 kristerkari