Skip to content

Commit

Permalink
Support pure comments and styles attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Mar 8, 2022
1 parent 69bd7c1 commit 9144711
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 138 deletions.
31 changes: 31 additions & 0 deletions docs/advanced-features/compiler.md
Expand Up @@ -187,6 +187,37 @@ First, update to the latest version of Next.js: `npm install next@latest`. Then,
}
```

### Emotion

We're working to port `@emotion/babel-plugin` to the Next.js Compiler.

First, update to the latest version of Next.js: `npm install next@latest`. Then, update your `next.config.js` file:

```js
// next.config.js

module.exports = {
compiler: {
//
emotion: boolean | {
// default is true. It will be disabled when build type is production.
sourceMap?: boolean,
// default is 'dev-only'.
autoLabel?: 'never' | 'dev-only' | 'always',
// default is '[local]'.
// Allowed values: `[local]` `[filename]` and `[dirname]`
// 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 with the name of the variable the result is assigned to.
labelFormat?: string,
},
},
}
```

Only `importMap` in `@emotion/babel-plugin` is not supported for now.

## Experimental Features

### Minification
Expand Down
4 changes: 1 addition & 3 deletions examples/with-emotion-swc/next.config.js
Expand Up @@ -3,9 +3,7 @@
const nextConfig = {
reactStrictMode: true,
compiler: {
emotion: {
enabled: true,
},
emotion: true,
},
}

Expand Down
9 changes: 7 additions & 2 deletions examples/with-emotion-swc/pages/_app.js
@@ -1,10 +1,15 @@
import createCache from '@emotion/cache'
import { CacheProvider } from '@emotion/react'

import { globalStyles } from '../shared/styles'

const cache = createCache({ key: 'next' })

const App = ({ Component, pageProps }) => (
<>
<CacheProvider value={cache}>
{globalStyles}
<Component {...pageProps} />
</>
</CacheProvider>
)

export default App
8 changes: 7 additions & 1 deletion examples/with-emotion-swc/pages/index.js
@@ -1,7 +1,13 @@
import { css } from '@emotion/react'
import { Animated, Basic, bounce, Combined, Pink } from '../shared/styles'

const Home = () => (
<div>
<div
css={css`
display: flex;
flex-direction: column;
`}
>
<Basic>Cool Styles</Basic>
<Pink>Pink text</Pink>
<Combined>
Expand Down

0 comments on commit 9144711

Please sign in to comment.