-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Babel plugin #62
Babel plugin #62
Changes from 8 commits
33fea5f
b6acb46
8edd7b0
028cef8
cf566a7
ad8c1c1
6b4bf98
13c7ee3
8652658
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import React from 'react'; | ||
import SectionLayout from '../SectionLayout'; | ||
import CodeBlock from '../CodeBlock'; | ||
import Code from '../Code'; | ||
import Note from '../Note'; | ||
import Link from '../Link' | ||
|
||
const installNPM = ` | ||
npm install --save-dev babel-plugin-styled-components | ||
`.trim(); | ||
|
||
const usage = ` | ||
{ | ||
"plugins": ["styled-components"] | ||
} | ||
`.trim(); | ||
|
||
const ssr = ` | ||
{ | ||
"plugins": [ | ||
["styled-components", { | ||
"ssr": true | ||
}] | ||
] | ||
} | ||
`.trim(); | ||
|
||
const displayName = ` | ||
{ | ||
"plugins": [ | ||
["styled-components", { | ||
"displayName": false | ||
}] | ||
] | ||
} | ||
`.trim(); | ||
|
||
const preprocess = ` | ||
{ | ||
"plugins": [ | ||
["styled-components", { | ||
"preprocess": true | ||
}] | ||
] | ||
} | ||
`.trim(); | ||
|
||
const minify = ` | ||
{ | ||
"plugins": [ | ||
["styled-components", { | ||
"minify": false | ||
}] | ||
] | ||
} | ||
`.trim(); | ||
|
||
const transpilation = ` | ||
{ | ||
"plugins": [ | ||
["styled-components", { | ||
"transpileTemplateLiterals": false | ||
}] | ||
] | ||
} | ||
`.trim(); | ||
|
||
const BabelPlugin = () => | ||
<SectionLayout title="Babel Plugin" labels={['v2']}> | ||
<p> | ||
This plugin adds support for server-side rendering, for minification of | ||
styles and gives you a nicer debugging experience. | ||
</p> | ||
<SectionLayout sub title="Usage"> | ||
<p>Install the babel-plugin first:</p> | ||
<CodeBlock code={installNPM} language="node" /> | ||
<p>Then add it to your babel configuration like so:</p> | ||
<CodeBlock code={usage} language="node" /> | ||
</SectionLayout> | ||
<SectionLayout sub title="Server-side rendering"> | ||
<Note>This option is turned off by default</Note> | ||
<p> | ||
By adding a unique identifier to every styled component this plugin | ||
avoids checksum mismatches due to different class generation on the | ||
client and on the server. If you do not use this plugin and try to | ||
server-side render styled-components React will complain. | ||
</p> | ||
<p> | ||
You can enable it with the <Code>ssr</Code> option: | ||
</p> | ||
<CodeBlock code={ssr} language="node" /> | ||
</SectionLayout> | ||
<SectionLayout sub title="Better debugging"> | ||
<p> | ||
This options adds the components' name and displayName to the class name | ||
attached to the DOM node. In your browser's DevTools you'll see:{' '} | ||
<Code> | ||
<button class="sc-Button-asdf123 asdf123" /> | ||
</Code>{' '} | ||
instead of just <Code><button class="asdf123" /></Code>. | ||
</p> | ||
<p> | ||
This also adds support for showing your components' real name in the | ||
React DevTools. Consider writing a styled component that renders a{' '} | ||
<Code>button</Code> element, called <Code>MyButton</Code>. It will | ||
normally show up as <Code><styled.button></Code> for all of your | ||
components, but with this plugin they show{' '} | ||
<Code><MyButton /></Code>. | ||
</p> | ||
<p> | ||
This makes it easier to find your components and to figure out where | ||
they live in your app. | ||
</p> | ||
<p> | ||
If you don't need this feature, you can disable it with the{' '} | ||
<Code>displayName</Code> option: | ||
</p> | ||
<CodeBlock code={displayName} language="node" /> | ||
</SectionLayout> | ||
<SectionLayout sub title="Preprocessing"> | ||
<Note> | ||
This is experimental and we don't yet know of all limitations and bugs! | ||
Consider this non-production ready for now. ⚠️ | ||
</Note> | ||
<p> | ||
This plugin preprocesses your styles with stylis and uses the{' '} | ||
<Code>no-parser.js</Code> entrypoint on styled-components. | ||
</p> | ||
<p> | ||
This effectively removes stylis from your runtime bundle and should | ||
slightly improve runtime performance and shrink your bundle size. | ||
</p> | ||
<p> | ||
It automatically disables the <Code>minify</Code> option, since stylis | ||
already does some minification on your CSS. | ||
</p> | ||
<p> | ||
You can enable preprocessing with the <Code>preprocess</Code> option: | ||
</p> | ||
<CodeBlock code={preprocess} language="node" /> | ||
</SectionLayout> | ||
<SectionLayout sub title="Minification"> | ||
<Note> | ||
This option is turned on by default. If you experience mangled CSS | ||
results, turn it off and open an issue please. | ||
</Note> | ||
<p> | ||
This plugin minifies your styles in the tagged template literals, giving | ||
you big bundle size savings. | ||
</p> | ||
<Note> | ||
This operation may potentially break your styles in some rare cases, so | ||
we recommend to keep this option enabled in development if it's enabled | ||
in the production build. | ||
</Note> | ||
<p> | ||
You can disable minification with the <Code>minify</Code> option: | ||
</p> | ||
<CodeBlock code={minify} language="node" /> | ||
</SectionLayout> | ||
<SectionLayout sub title="Template String Transpilation"> | ||
<p> | ||
We also transpile <Code>styled-components</Code> tagged template | ||
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. This should go into a new section, since it's a separate option actually. 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. What should go in this section ? Just this paragraph ? 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. Yea, this entire part about the template string transpilation 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. |
||
literals down to a smaller representation than what Babel normally does, | ||
because <Code>styled-components</Code> template literals don't need to | ||
be 100% spec compliant. see{' '} | ||
<Link href="#tagged-template-literals">Tagged Template Literals</Link> for | ||
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. Sorry for not being clear enough on this :( You'll have to pass the 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. Got it ! It does look better now :p |
||
more information about that) You can use the {' '} | ||
<Code>transpileTemplateLiterals</Code> option to turn this feature off. | ||
</p> | ||
<CodeBlock code={transpilation} language="node" /> | ||
</SectionLayout> | ||
</SectionLayout>; | ||
|
||
export default BabelPlugin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,69 +6,94 @@ | |
"sections": [ | ||
{ | ||
"title": "Motivation" | ||
}, { | ||
}, | ||
{ | ||
"title": "Installation" | ||
}, { | ||
}, | ||
{ | ||
"title": "Getting Started" | ||
}, { | ||
}, | ||
{ | ||
"title": "Passed props" | ||
}, { | ||
}, | ||
{ | ||
"title": "Adapting based on props" | ||
}, { | ||
}, | ||
{ | ||
"title": "Styling any components" | ||
}, { | ||
}, | ||
{ | ||
"title": "Extending styles" | ||
}, { | ||
}, | ||
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. Prettier auto did this , should I revert ? |
||
{ | ||
"title": "Attaching additional props" | ||
}, { | ||
}, | ||
{ | ||
"title": "Animations" | ||
}, { | ||
}, | ||
{ | ||
"title": "React Native" | ||
} | ||
] | ||
}, { | ||
}, | ||
{ | ||
"title": "Advanced", | ||
"pathname": "advanced", | ||
"sections": [ | ||
{ | ||
"title": "Theming" | ||
}, { | ||
}, | ||
{ | ||
"title": "Refs" | ||
}, { | ||
}, | ||
{ | ||
"title": "Security" | ||
}, { | ||
}, | ||
{ | ||
"title": "Existing CSS" | ||
}, { | ||
}, | ||
{ | ||
"title": "Media Templates" | ||
}, { | ||
}, | ||
{ | ||
"title": "Tagged Template Literals" | ||
}, { | ||
}, | ||
{ | ||
"title": "Server Side Rendering" | ||
}, | ||
{ | ||
"title": "Babel Plugin" | ||
} | ||
] | ||
}, { | ||
}, | ||
{ | ||
"title": "API Reference", | ||
"pathname": "api", | ||
"sections": [ | ||
{ | ||
"title": "Primary" | ||
}, { | ||
}, | ||
{ | ||
"title": "Helpers" | ||
}, { | ||
}, | ||
{ | ||
"title": "Supported CSS" | ||
}, { | ||
}, | ||
{ | ||
"title": "Flow" | ||
}, { | ||
}, | ||
{ | ||
"title": "TypeScript" | ||
} | ||
] | ||
}, { | ||
}, | ||
{ | ||
"title": "FAQs", | ||
"pathname": "faqs", | ||
"sections": [ | ||
{"title": "Can I nest rules?"}, | ||
{"title": "Can I refer to other components?"}, | ||
{"title": "Can I use css frameworks?"} | ||
{ "title": "Can I nest rules?" }, | ||
{ "title": "Can I refer to other components?" }, | ||
{ "title": "Can I use css frameworks?" } | ||
] | ||
} | ||
] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import React from 'react' | ||
import DocsLayout from '../../components/DocsLayout' | ||
import NextPage from '../../components/NextPage' | ||
import React from 'react'; | ||
import DocsLayout from '../../components/DocsLayout'; | ||
import NextPage from '../../components/NextPage'; | ||
|
||
import Theming from '../../components/advanced/theming' | ||
import Refs from '../../components/advanced/refs' | ||
import Security from '../../components/advanced/security' | ||
import ExistingCSS from '../../components/advanced/existing-css' | ||
import MediaTemplates from '../../components/advanced/media-templates' | ||
import TaggedTemplateLiterals from '../../components/advanced/tagged-template-literals' | ||
import ServerSideRendering from '../../components/advanced/server-side-rendering' | ||
import Theming from '../../components/advanced/theming'; | ||
import Refs from '../../components/advanced/refs'; | ||
import Security from '../../components/advanced/security'; | ||
import ExistingCSS from '../../components/advanced/existing-css'; | ||
import MediaTemplates from '../../components/advanced/media-templates'; | ||
import TaggedTemplateLiterals from '../../components/advanced/tagged-template-literals'; | ||
import ServerSideRendering from '../../components/advanced/server-side-rendering'; | ||
import BabelPlugin from '../../components/advanced/babel-plugin'; | ||
|
||
const Advanced = () => ( | ||
const Advanced = () => | ||
<DocsLayout title="Advanced"> | ||
<Theming /> | ||
<Refs /> | ||
|
@@ -19,12 +20,9 @@ const Advanced = () => ( | |
<MediaTemplates /> | ||
<TaggedTemplateLiterals /> | ||
<ServerSideRendering /> | ||
<BabelPlugin /> | ||
|
||
<NextPage | ||
href="/docs/api" | ||
title="API Reference" | ||
/> | ||
</DocsLayout> | ||
) | ||
<NextPage href="/docs/api" title="API Reference" /> | ||
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. Prettier again 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. No worries! I might add prettier soon anyway 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. Awesome ! I can do that if you want 👍 |
||
</DocsLayout>; | ||
|
||
export default Advanced | ||
export default Advanced; |
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.
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.
I'm sorry ?
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.
Just indicating that we need to replace the mention of "this plugin" with "this option" since each section only talks about a single option :)