# babel-plugin-pure-static-props

> Fixes issue with tree shaking that can occur when using static properties on React components using styled-components

Latest version **0.2.0** (published 2021-03-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-pure-static-props
pnpm add babel-plugin-pure-static-props
yarn add babel-plugin-pure-static-props
bun add babel-plugin-pure-static-props
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-03-10 |
| First published | 2021-03-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Matt Browne |
| Maintainers | mbrowne |
| Keywords | react, styled-components, tree shaking, code splitting, static properties, babel-plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-pure-static-props
- Repository: https://github.com/mbrowne/babel-plugin-pure-static-props
- Homepage: https://github.com/mbrowne/babel-plugin-pure-static-props#readme
- Issues: https://github.com/mbrowne/babel-plugin-pure-static-props/issues
- npm.io page: https://npm.io/package/babel-plugin-pure-static-props

## Dependencies (2)

- [@babel/plugin-syntax-jsx](https://npm.io/package/@babel/plugin-syntax-jsx.md) ^7.12.13
- [@babel/helper-annotate-as-pure](https://npm.io/package/@babel/helper-annotate-as-pure.md) ^7.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2021-03-10

## README

# babel-plugin-pure-static-props

Fixes an issue with tree shaking that can occur when using static properties on React components using styled-components.

This plugin replaces static property assignments on React components (e.g. `MyComponent.defaultProps = {...}`) with `Object.assign()` statements annotated with `/*#__PURE__*/` comments so that tree-shaking will work correctly.

## Install

```bash
npm i -D babel-plugin-pure-static-props
```

Or:

```bash
yarn add -D babel-plugin-pure-static-props
```

Then add the plugin to your Babel config as explained in the [Babel documentation](https://babeljs.io/docs/en/options#plugin-and-preset-options).

Example `babel.config.js`:

```js
module.exports = {
  presets: ['@babel/preset-env'],
  plugins: [
    '@babel/plugin-proposal-class-properties',
    'babel-plugin-pure-static-props',
  ],
}
```

## Note on styled components

The tree-shaking issue with static properties on React components also affects [styled components](https://styled-components.com/). This plugin only addresses tree-shaking for regular React components; it will not work on components created using the `styled` helper.

A fix for styled components is in this PR: https://github.com/styled-components/babel-plugin-styled-components/pull/248.

---
_Source: https://npm.io/package/babel-plugin-pure-static-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
