{"id":17963348,"url":"https://github.com/kristerkari/react-native-postcss-transformer","last_synced_at":"2026-03-27T04:56:37.063Z","repository":{"id":28459941,"uuid":"118381079","full_name":"kristerkari/react-native-postcss-transformer","owner":"kristerkari","description":"Use PostCSS to style your React Native apps.","archived":false,"fork":false,"pushed_at":"2024-10-07T08:08:00.000Z","size":1006,"stargazers_count":28,"open_issues_count":7,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-13T21:44:28.372Z","etag":null,"topics":["loader","postcss","react-native","transformer"],"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-21T22:54:12.000Z","updated_at":"2025-05-27T06:56:37.000Z","dependencies_parsed_at":"2024-02-25T03:28:49.137Z","dependency_job_id":"3014e353-009b-4fbc-9533-86ff4deea053","html_url":"https://github.com/kristerkari/react-native-postcss-transformer","commit_stats":{"total_commits":76,"total_committers":4,"mean_commits":19.0,"dds":0.3421052631578947,"last_synced_commit":"4ad3d88b85011e8ab57324a1e12453b8e89d4097"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/kristerkari/react-native-postcss-transformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-postcss-transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-postcss-transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-postcss-transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-postcss-transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristerkari","download_url":"https://codeload.github.com/kristerkari/react-native-postcss-transformer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristerkari%2Freact-native-postcss-transformer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271274238,"owners_count":24730975,"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","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["loader","postcss","react-native","transformer"],"created_at":"2024-10-29T11:34:44.034Z","updated_at":"2026-03-27T04:56:31.999Z","avatar_url":"https://github.com/kristerkari.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-postcss-transformer [![NPM version](http://img.shields.io/npm/v/react-native-postcss-transformer.svg)](https://www.npmjs.org/package/react-native-postcss-transformer) [![Downloads per month](https://img.shields.io/npm/dm/react-native-postcss-transformer.svg)](http://npmcharts.com/compare/react-native-postcss-transformer?periodLength=30) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github)\n\nUse [PostCSS](https://github.com/postcss/postcss) to style your React Native apps.\n\nBehind the scenes the PostCSS 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 (using [postcss-css-variables](https://github.com/MadLittleMods/postcss-css-variables) plugin):\n\n```css\n:root {\n  --blue-color: blue;\n}\n\n.myClass {\n  color: var(--blue-color);\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-postcss-transformer postcss\n```\n\nor\n\n```sh\nyarn add --dev react-native-postcss-transformer postcss\n```\n\n### Step 2: Add your PostCSS config and install your PostCSS plugins\n\nAdd your PostCSS configuration to [one of the supported config formats](https://github.com/michael-ciniawsky/postcss-load-config), e.g. `package.json`, `.postcssrc`, `postcss.config.js`, etc.\n\n### Step 3: 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(\"./postcss-transformer.js\")\n  };\n  config.resolver = {\n    ...resolver,\n    sourceExts: [...sourceExts, \"css\", \"pcss\"]\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(\"./postcss-transformer.js\")\n  },\n  resolver: {\n    sourceExts: [...sourceExts, \"css\", \"pcss\"]\n  }\n};\n\nmodule.exports = mergeConfig(defaultConfig, config);\n```\n\n### Step 4: Add transformer file\n\nCreate `postcss-transformer.js` file to your project's root and specify supported extensions:\n\n```js\nconst upstreamTransformer = require(\"@react-native/metro-babel-transformer\");\nconst postcssTransformer = require(\"react-native-postcss-transformer\");\nconst postCSSExtensions = [\"css\", \"pcss\"]; // \u003c-- Add other extensions if needed.\n\nmodule.exports.transform = function ({ src, filename, ...rest }) {\n  if (postCSSExtensions.some((ext) =\u003e filename.endsWith(\".\" + ext))) {\n    return postcssTransformer.transform({ src, filename, ...rest });\n  }\n  return upstreamTransformer.transform({ src, filename, ...rest });\n};\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- [postcss-load-config](https://github.com/michael-ciniawsky/postcss-load-config)\n\n## TODO\n\n- Find a way to make the configuration cleaner by only having to add `metro.config.js` to a project, https://github.com/kristerkari/react-native-postcss-transformer/issues/1.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristerkari%2Freact-native-postcss-transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristerkari%2Freact-native-postcss-transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristerkari%2Freact-native-postcss-transformer/lists"}