JSPM

react-native-stylus-transformer

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22
  • Score
    100M100P100Q56061F
  • License MIT

Stylus transformer for react-native

Package Exports

  • react-native-stylus-transformer

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-stylus-transformer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-native-stylus-transformer

NPM version PRs Welcome

Load Stylus files to react native style objects.

This transformer can be used together with React Native CSS modules.

Usage

Step 1: Install

yarn add --dev react-native-stylus-transformer stylus

Step 2: Configure the react native packager

Add this to your rn-cli.config.js (make one if you don't have one already):

module.exports = {
  getTransformModulePath() {
    return require.resolve("react-native-stylus-transformer");
  },
  getSourceExts() {
    return ["js", "jsx", "styl"];
  }
};

...or if you are using Expo, in app.json:

{
  "expo": {
    "packagerOpts": {
      "sourceExts": ["js", "jsx", "styl"],
      "transformer": "node_modules/react-native-stylus-transformer/index.js"
    }
  }
}

How does it work?

Your App.styl file might look like this:

.myClass {
  color: blue;
}
.myOtherClass {
  color: red;
}

When you import your stylesheet:

import styles from "./App.styl";

Your imported styles will look like this:

var styles = {
  myClass: {
    color: "blue"
  },
  myOtherClass: {
    color: "red"
  }
};

You can then use that style object with an element:

<MyElement style={styles.myClass} />