{"id":17963341,"url":"https://github.com/kristerkari/react-native-css-transformer","last_synced_at":"2025-04-06T16:14:54.775Z","repository":{"id":28182481,"uuid":"116605085","full_name":"kristerkari/react-native-css-transformer","owner":"kristerkari","description":"Use CSS to style your React Native apps.","archived":false,"fork":false,"pushed_at":"2024-11-25T11:26:12.000Z","size":1211,"stargazers_count":40,"open_issues_count":7,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T15:11:08.549Z","etag":null,"topics":["css","loader","react-native","transform"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kristerkari.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-07T22:47:01.000Z","updated_at":"2025-03-05T02:09:13.000Z","dependencies_parsed_at":"2024-09-06T01:49:36.225Z","dependency_job_id":"7054423c-ee8f-41f6-aae8-dd4a422d4c80","html_url":"https://github.com/kristerkari/react-native-css-transformer","commit_stats":{"total_commits":61,"total_committers":3,"mean_commits":"20.333333333333332","dds":"0.16393442622950816","last_synced_commit":"a40fa6ff28b1fe50b73f88e46024bd3cd716cf95"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-css-transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-css-transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-css-transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-css-transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristerkari","download_url":"https://codeload.github.com/kristerkari/react-native-css-transformer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509238,"owners_count":20950232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","loader","react-native","transform"],"created_at":"2024-10-29T11:34:02.900Z","updated_at":"2025-04-06T16:14:54.754Z","avatar_url":"https://github.com/kristerkari.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-css-transformer [![NPM version](http://img.shields.io/npm/v/react-native-css-transformer.svg)](https://www.npmjs.org/package/react-native-css-transformer) [![Downloads per month](https://img.shields.io/npm/dm/react-native-css-transformer.svg)](http://npmcharts.com/compare/react-native-css-transformer?periodLength=30) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github)\n\nUse CSS to style your React Native apps.\n\nBehind the scenes the `.css` files are transformed to [react native style objects](https://facebook.github.io/react-native/docs/style.html) (look at the examples).\n\n\u003e This transformer can be used together with [React Native CSS modules](https://github.com/kristerkari/react-native-css-modules).\n\n## How does it work?\n\nYour `App.css` file might look like this:\n\n```css\n.myClass {\n  color: blue;\n}\n.myOtherClass {\n  color: red;\n}\n.my-dashed-class {\n  color: green;\n}\n```\n\nWhen you import your stylesheet:\n\n```js\nimport styles from \"./App.css\";\n```\n\nYour imported styles will look like this:\n\n```js\nvar styles = {\n  myClass: {\n    color: \"blue\"\n  },\n  myOtherClass: {\n    color: \"red\"\n  },\n  \"my-dashed-class\": {\n    color: \"green\"\n  }\n};\n```\n\nYou can then use that style object with an element:\n\n**Plain React Native:**\n\n```jsx\n\u003cMyElement style={styles.myClass} /\u003e\n\n\u003cMyElement style={styles[\"my-dashed-class\"]} /\u003e\n```\n\n**[React Native CSS modules](https://github.com/kristerkari/react-native-css-modules) using [className](https://github.com/kristerkari/babel-plugin-react-native-classname-to-style) property:**\n\n```jsx\n\u003cMyElement className={styles.myClass} /\u003e\n\n\u003cMyElement className={styles[\"my-dashed-class\"]} /\u003e\n```\n\n**[React Native CSS modules](https://github.com/kristerkari/react-native-css-modules) using [styleName](https://github.com/kristerkari/babel-plugin-react-native-stylename-to-style) property:**\n\n```jsx\n\u003cMyElement styleName=\"myClass my-dashed-class\" /\u003e\n```\n\n## Installation and configuration\n\n### Step 1: Install\n\n```sh\nnpm install --save-dev react-native-css-transformer\n```\n\nor\n\n```sh\nyarn add --dev react-native-css-transformer\n```\n\n### Step 2: Configure the react native packager\n\n#### For Expo SDK v41.0.0 or newer\n\nMerge the contents from your project's `metro.config.js` file with this config (create the file if it does not exist already).\n\n`metro.config.js`:\n\n```js\nconst { getDefaultConfig } = require(\"expo/metro-config\");\n\nmodule.exports = (() =\u003e {\n  const config = getDefaultConfig(__dirname);\n\n  const { transformer, resolver } = config;\n\n  config.transformer = {\n    ...transformer,\n    babelTransformerPath: require.resolve(\"react-native-css-transformer\")\n  };\n  config.resolver = {\n    ...resolver,\n    sourceExts: [...sourceExts, \"css\"]\n  };\n\n  return config;\n})();\n```\n\n---\n\n#### For React Native v0.72.1 or newer\n\nMerge the contents from your project's `metro.config.js` file with this config (create the file if it does not exist already).\n\n`metro.config.js`:\n\n```js\nconst { getDefaultConfig, mergeConfig } = require(\"@react-native/metro-config\");\n\nconst defaultConfig = getDefaultConfig(__dirname);\nconst { assetExts, sourceExts } = defaultConfig.resolver;\n\n/**\n * Metro configuration\n * https://reactnative.dev/docs/metro\n *\n * @type {import('metro-config').MetroConfig}\n */\nconst config = {\n  transformer: {\n    babelTransformerPath: require.resolve(\"react-native-css-transformer\")\n  },\n  resolver: {\n    sourceExts: [...sourceExts, \"css\"]\n  }\n};\n\nmodule.exports = mergeConfig(defaultConfig, config);\n```\n\n## CSS Custom Properties (CSS variables)\n\n```css\n:root {\n  --text-color: blue;\n}\n\n.blue {\n  color: var(--text-color);\n}\n```\n\nCSS variables are not supported by default, but you can add support for them by using [PostCSS](https://postcss.org/) and [postcss-css-variables](https://github.com/MadLittleMods/postcss-css-variables#readme) plugin.\n\nStart by installing dependencies:\n\n```sh\nyarn add postcss postcss-css-variables react-native-postcss-transformer --dev\n```\n\nRemove CSS transformer from the project:\n\n```sh\nyarn remove react-native-css-transformer\n```\n\nAdd `postcss-css-variables` to your PostCSS configuration with [one of the supported config formats](https://github.com/michael-ciniawsky/postcss-load-config), e.g. `package.json`, `.postcssrc`, `postcss.config.js`, etc.\n\nAfter that replace the transformer name in your Metro config file (`metro.config.js`):\n\n```diff\n-require.resolve(\"react-native-css-transformer\")\n+require.resolve(\"react-native-postcss-transformer\")\n```\n\n## Dependencies\n\nThis library has the following Node.js modules as dependencies:\n\n- [css-to-react-native-transform](https://github.com/kristerkari/css-to-react-native-transform)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristerkari%2Freact-native-css-transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristerkari%2Freact-native-css-transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristerkari%2Freact-native-css-transformer/lists"}