vue-emotion
emotion is the Next Generation of CSS-in-JS.
Install
yarn add emotion vue-emotion
Table of Contents
Usage
Add the babel plugin first:
{
"plugins": [
"emotion/babel"
]
}
Then create your styled component:
import styled from 'vue-emotion'
const Button = styled('button')`
font-size: 15px;
`
const PinkButton = styled(Button)`
color: pink
`
new Vue({
render() {
return (
<div>
<Button>normal button</Button>
<PinkButton>pink button</PinkButton>
</div>
)
}
})
Refer to https://github.com/tkh44/emotion for more docs.
Server-side rendering
The easy way, use emotion's extractStatic mode:
{
"plugins": [
["emotion/babel", { "extractStatic": true }]
]
}
Check out the doc about extractStatic.
Then when you write something like:
import styled from 'vue-emotion'
const H1 = styled('h1')`
color: #ffd43b;
`
It will be compiled to:
import './h1.emotion.css'
import styled from 'vue-emotion'
const H1 = styled('h1', 'css-duiy4a')
Basically you can treat .emotion.css
as normal CSS file and configure the loader for it in webpack config, since we're trying to make SSR work, you will need vue-style-loader
instead of style-loader
for it.
The alternative way
Check out https://github.com/tkh44/emotion/blob/master/docs/ssr.md, it does not support streaming though.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
vue-emotion © EGOIST, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).
github.com/egoist · GitHub @EGOIST · Twitter @_egoistlily