Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Babel output a little bit #1656

Merged
merged 11 commits into from
Jan 5, 2020
Prev Previous commit
Next Next commit
Adjust docs about new autoLabel values
  • Loading branch information
Andarist committed Jan 1, 2020
commit 00b06dd2c814aa0c02474c7156272be7794b4a40
14 changes: 10 additions & 4 deletions packages/babel-plugin-emotion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ _Defaults Shown_
{
// sourceMap is on by default but source maps are dead code eliminated in production
"sourceMap": true,
"autoLabel": process.env.NODE_ENV !== 'production',
"autoLabel": "dev-only",
"labelFormat": "[local]",
"cssPropOptimization": true
}
Expand Down Expand Up @@ -183,7 +183,7 @@ This option enables the following:

### `autoLabel`

`boolean`, defaults to `process.env.NODE_ENV !== 'production'`.
`'dev-only' | 'always' | 'never'`, , defaults to `dev-only`.

This option enables the following:

Expand All @@ -194,6 +194,12 @@ This option enables the following:
(Eg. `iconStyles$1` will become `iconStyles1`) because `$` is not valid
[CSS ClassName Selector](https://stackoverflow.com/questions/448981/which-characters-are-valid-in-css-class-names-selectors#449000)

Each possible value for this option produces different output code:

- with `dev-only` we optimize the production code, so there are no labels added there, but at the same time we keep labels for development environments,
- with `always` we always add labels when possible,
- with `never` we disable this entirely and no labels are added.

#### css

**In**
Expand All @@ -214,7 +220,7 @@ const brownStyles = /*#__PURE__*/ css({ color: 'brown' }, 'label:brownStyles;')

`string`, defaults to `"[local]"`.

This option only works when `autoLabel` is set to `true`. It allows you to
This option only works when `autoLabel` is set to `'dev-only'` or `'always'`. It allows you to
define the format of the resulting `label`. The format is defined via string where
variable parts are enclosed in square brackets `[]`.
For example `labelFormat: "my-classname--[local]"`, where `[local]` will be replaced
Expand All @@ -235,7 +241,7 @@ be prepended automatically.

```javascript
// BrownView.js
// autoLabel: true
// autoLabel: 'dev-only'
// labelFormat: '[filename]--[local]'
const brownStyles = css({ color: 'brown' })
```
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-preset-css-prop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ yarn add @emotion/babel-preset-css-prop
+ [
+ "@emotion/babel-preset-css-prop",
+ {
+ "autoLabel": true,
+ "autoLabel": "dev-only",
+ "labelFormat": "[local]"
+ }
+ ]
Expand All @@ -40,7 +40,7 @@ yarn add @emotion/babel-preset-css-prop
- [
- "emotion",
- {
- "autoLabel": true,
- "autoLabel": "dev-only",
- "labelFormat": "[local]"
- }
- ]
Expand Down Expand Up @@ -146,7 +146,7 @@ Options for both `babel-plugin-emotion` and `@babel/plugin-transform-react-jsx`
"presets": [
"@emotion/babel-preset-css-prop",
{
"autoLabel": true,
"autoLabel": "dev-only",
"labelFormat": "[local]",
"useBuiltIns": false,
"throwIfNamespace": true
Expand Down