-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
readme and doc consolidation updates #408
Changes from all commits
b4b0fe6
1d85f5e
f1edabc
a4f747f
cfcc752
a90d0c5
ce6c095
024a18a
58f76c2
946c982
401288b
861444b
e16489f
5834ad2
9276fc6
eb0b351
69588f4
2cb4154
f836dc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## Usage with Babel | ||
|
||
The Babel Plugin is highly recommended, but not required in version 8 and above. | ||
|
||
See the [installation instructions](install.md). | ||
|
||
### Features which are enabled with the babel plugin | ||
|
||
### styled.element Syntax | ||
`styled('div')` will work without the plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see an explanation of the two syntax types and the reason for using one over the other. It probably should go in the 'getting started' section (if there is one..) though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a getting started doc on deck for my next PR. I'll need some help understanding the big differences between syntaxes |
||
|
||
### Minification | ||
Any leading/trailing space between properties in your `css` and `styled` blocks is removed. This can reduce the size of your final bundle. | ||
|
||
### Dead Code Elimination | ||
Uglifyjs will use the injected `/*#__PURE__*/` flag comments to mark your `css` and `styled` blocks as candidates for dead code elimination. | ||
|
||
### Static Extraction | ||
Generated CSS that is eligible for extraction can be moved to an external css file. | ||
|
||
### Source Maps | ||
When enabled, navigate directly to the style declaration in your javascript file. | ||
|
||
### css as Prop | ||
Convenient helper for calling `css` and appending the generated className during compile time. | ||
|
||
## Babel Macros | ||
|
||
Instead of using emotion's babel plugin, you can use emotion with [`babel-macros`](/~https://github.com/kentcdodds/babel-macros). Add `babel-macros` to your babel config and import whatever you want from emotion but add `/macro` to the end. The macro is currently the same as inline mode. Currently every API except for the css prop is supported by the macro. | ||
|
||
```jsx | ||
import styled from 'react-emotion/macro' | ||
import { css, keyframes, fontFace, injectGlobal, flush, hydrate } from 'emotion/macro' | ||
``` | ||
|
||
For some context, check out this [issue](/~https://github.com/facebookincubator/create-react-app/issues/2730). |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,53 @@ | ||
[github](/~https://github.com/tkh44/emotion) | ||
[npm](https://npm.im/emotion) | ||
|
||
## Install | ||
|
||
```bash | ||
npm install --save emotion react-emotion babel-plugin-emotion | ||
``` | ||
|
||
**.babelrc** | ||
All `emotion` APIs are available from the `react-emotion` package. | ||
|
||
```javascript | ||
import styled, { css, injectGlobal } from 'react-emotion'; | ||
``` | ||
|
||
### .babelrc | ||
|
||
[More information on the babel plugin](babel.md) | ||
|
||
_`"emotion"` must be the **first plugin** in your babel config `plugins` list._ | ||
|
||
Takes optional configs: | ||
- [extractStatic](babel.md#Static-Extraction) _{boolean}_ | ||
- [sourceMap](babel.md#Static-Extraction) _{boolean}_ | ||
```json | ||
{ | ||
"plugins": [ | ||
"emotion" | ||
["emotion"] | ||
] | ||
} | ||
``` | ||
|
||
**Notes:** | ||
- Make sure `"emotion"` is the first plugin. | ||
- If you are using Babel's env option in your `.babelrc` file, ensure that emotion is first in every environment's list of plugins. | ||
If using Babel's env option emotion must also be first for each environment. | ||
```json | ||
{ | ||
"env": { | ||
"production": { | ||
"plugins": ["emotion", "some-other-plugin"] | ||
"plugins": [ | ||
"emotion", | ||
[...all other babel plugins...] | ||
] | ||
} | ||
}, | ||
"plugins": ["emotion"] | ||
} | ||
``` | ||
### Preact | ||
|
||
### Preact | ||
Import `preact-emotion` instead of `react-emotion` and use it the same way you would with React. | ||
|
||
If you're using [Preact](/~https://github.com/developit/preact) instead of [React](/~https://github.com/facebook/react), install [`preact-emotion`](./preact.md). The babel setup remains the same. | ||
```jsx | ||
import styled from 'preact-emotion' | ||
|
||
const SomeComponent = styled.div` | ||
display: flex; | ||
` | ||
``` |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greggb @tkh44 there are quite a few babel options (e.g. sourcemaps, inline etc etc).. I think they should be documented here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely - I'm not sure of all the options