You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-8Lines changed: 21 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,11 @@
1
1
# `babel-plugin-styled-components`
2
2
3
-
This plugin adds support for server-side rendering, for minification of styles and gives you a nicer debugging experience when using `styled-components`.
3
+
This plugin is a highly recommended supplement to the base styled-components library, offering some useful features:
4
+
5
+
* consistently hashed component classNames between environments (a must for server-side rendering)
6
+
* automatic library usage tweaks that allow for some bytes to be dropped from your bundle
7
+
* better debugging through automatic annotation of your styled components based on their context in the file system, etc.
8
+
* various types of minification for styles and the tagged template literals styled-components uses
4
9
5
10
## Quick start
6
11
@@ -18,18 +23,26 @@ Then add it to your babel configuration:
Copy file name to clipboardExpand all lines: minification.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,15 @@ Wait, transpiling tagged template literals? Doesn't Babel do this natively?
6
6
7
7
## Transpiling tagged template literals
8
8
9
-
You're currently using Babel to transpile your ES2015 JavaScript to ES5-compliant code. one of your presets (`es2015`/`env`/`latest`) includes the `babel-plugin-transform-es2015-template-literals` transform to make tagged template literals work in older browsers, but there is a caveat. Output of that plugin is quite wordy. It's done this way to meet specification requirements:
9
+
You're currently using Babel to transpile your ES2015 JavaScript to ES5-compliant code. one of your presets (`es2015`/`env`/`latest`) includes the `babel-plugin-transform-es2015-template-literals` transform to make tagged template literals work in older browsers, but there is a caveat. Output of that plugin is quite wordy. It's done this way to meet specification requirements:
10
10
11
11
```JS
12
12
// processed with babel-preset-latest
13
13
14
14
var _templateObject =_taggedTemplateLiteral(['width: 100%;'], ['width: 100%;']);
var Simple =_styledComponents2.default.div(_templateObject);
17
-
```
17
+
```
18
18
19
19
`styled-components` styling code does not require full spec compatibility. This plugin will transpile template literals attached to styled-component to a slightly different form which still works in older browsers but has a much smaller footprint.
20
20
@@ -34,19 +34,21 @@ keyframe``
34
34
css``
35
35
36
36
// But this will not be converted
37
-
`some text`
37
+
'some text'
38
38
39
39
// In next example outer template literal will be converted because it's attached to component factory,
40
40
// but inner template literals will not be touched
41
-
styled.div`color: ${ light ?`white`:`black`};`
41
+
styled.div`
42
+
color: ${ light ?'white':'black'};
43
+
;`
42
44
```
43
45
44
46
You can disable this feature with `transpileTemplateLiterals` option:
0 commit comments