Skip to content
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

Chore/stable swc compiler options #34074

Merged
merged 24 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b25340c
Make relay a stable compiler option
padmaia Feb 7, 2022
d3fbea9
Make styledComponents a stable compiler option
padmaia Feb 7, 2022
552adf0
Make reactRemoveProperties stable compiler option
padmaia Feb 7, 2022
ee47a7d
Make experimentalDecorators a stable compiler opt
padmaia Feb 7, 2022
0f40ac5
Make removeConsole stable compiler option
padmaia Feb 7, 2022
0346b8d
Make importSource a stable compiler option
padmaia Feb 7, 2022
3a5ea34
Fix compiler doc
padmaia Feb 7, 2022
c633094
Add telemetry
padmaia Feb 8, 2022
125c857
Update test configs
padmaia Feb 8, 2022
8843611
Merge branch 'canary' into chore/stable-swc-compiler-options
padmaia Feb 8, 2022
bf267b4
Remove jsxImportSource configuration
padmaia Feb 8, 2022
bd7bb08
Pass tests
padmaia Feb 8, 2022
4d83c5b
Add warning for ignored options when Babel is used
padmaia Feb 8, 2022
9d53c79
Add cleanup of test files
padmaia Feb 8, 2022
aa52afc
Merge branch 'canary' into chore/stable-swc-compiler-options
padmaia Feb 8, 2022
ed8fe9c
Update docs/advanced-features/compiler.md
padmaia Feb 9, 2022
b58987b
Fix doc
padmaia Feb 9, 2022
e4006db
Add version history row
padmaia Feb 9, 2022
f6ed3c3
Update packages/next/build/webpack-config.ts
padmaia Feb 9, 2022
f6d8881
Change version ordering
padmaia Feb 9, 2022
6a744cf
Fix formatting
padmaia Feb 9, 2022
df51081
Add warnings to update config
padmaia Feb 9, 2022
84a8a3d
Add jest to supported features in compiler doc
padmaia Feb 9, 2022
87b9eaa
Merge branch 'canary' into chore/stable-swc-compiler-options
kodiakhq[bot] Feb 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 44 additions & 41 deletions docs/advanced-features/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ description: Learn about the Next.js Compiler, written in Rust, which transforms
<details open>
<summary><b>Version History</b></summary>

| Version | Changes |
| --------- | --------------------------------------------------------------- |
| `v12.0.0` | Next.js Compiler [introduced](https://nextjs.org/blog/next-12). |
| Version | Changes |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `v12.1.0` | Added support for Styled Components, Jest, Relay, Remove React Properties, Legacy Decorators, Remove Console, and jsxImportSource. |
| `v12.0.0` | Next.js Compiler [introduced](https://nextjs.org/blog/next-12). |

</details>

Expand All @@ -30,21 +31,7 @@ We chose to build on SWC for a few reasons:
- **WebAssembly:** Rust's support for WASM is essential for supporting all possible platforms and taking Next.js development everywhere.
styfle marked this conversation as resolved.
Show resolved Hide resolved
- **Community:** The Rust community and ecosystem are amazing and still growing.

## Experimental Features

### Minification

You can opt-in to using the Next.js compiler for minification. This is 7x faster than Terser.

```js
// next.config.js

module.exports = {
swcMinify: true,
}
```

If you have feedback about `swcMinify`, please share it on the [feedback discussion](https://github.com/vercel/next.js/discussions/30237).
## Supported Features

### Styled Components

Expand All @@ -56,7 +43,7 @@ First, update to the latest version of Next.js: `npm install next@latest`. Then,
// next.config.js

module.exports = {
experimental: {
compiler: {
// ssr and displayName are configured by default
styledComponents: true,
},
Expand Down Expand Up @@ -101,7 +88,7 @@ To enable [Relay](https://relay.dev/) support:
```js
// next.config.js
module.exports = {
experimental: {
compiler: {
relay: {
// This should match relay.config.js
src: './',
Expand All @@ -123,7 +110,7 @@ To remove properties matching the default regex `^data-test`:
```js
// next.config.js
module.exports = {
experimental: {
compiler: {
reactRemoveProperties: true,
},
}
Expand All @@ -134,30 +121,14 @@ To remove custom properties:
```js
// next.config.js
module.exports = {
experimental: {
compiler: {
// The regexes defined here are processed in Rust so the syntax is different from
// JavaScript `RegExp`s. See https://docs.rs/regex.
reactRemoveProperties: { properties: ['^data-custom$'] },
},
}
```

### Legacy Decorators

Next.js will automatically detect `experimentalDecorators` in `jsconfig.json` or `tsconfig.json` and apply that. This is commonly used with older versions of libraries like `mobx`.

This flag is only supported for compatibility with existing applications. We do not recommend using legacy decorators in new applications.

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

```js
{
"compilerOptions": {
"experimentalDecorators": true
}
}
```

### Remove Console

This transform allows for removing all `console.*` calls in application code (not `node_modules`). Similar to `babel-plugin-transform-remove-console`.
Expand All @@ -167,7 +138,7 @@ Remove all `console.*` calls:
```js
// next.config.js
module.exports = {
experimental: {
compiler: {
removeConsole: true,
},
}
Expand All @@ -178,14 +149,30 @@ Remove `console.*` output except `console.error`:
```js
// next.config.js
module.exports = {
experimental: {
compiler: {
removeConsole: {
exclude: ['error'],
},
},
}
```

### Legacy Decorators

Next.js will automatically detect `experimentalDecorators` in `jsconfig.json` or `tsconfig.json`. Legacy decorators are commonly used with older versions of libraries like `mobx`.

This flag is only supported for compatibility with existing applications. We do not recommend using legacy decorators in new applications.

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

```js
{
"compilerOptions": {
"experimentalDecorators": true
}
}
```

### importSource

Next.js will automatically detect `jsxImportSource` in `jsconfig.json` or `tsconfig.json` and apply that. This is commonly used with libraries like Theme UI.
Expand All @@ -195,11 +182,27 @@ First, update to the latest version of Next.js: `npm install next@latest`. Then,
```js
{
"compilerOptions": {
"jsxImportSource": true
"jsxImportSource": 'preact'
}
}
```

## Experimental Features

### Minification

You can opt-in to using the Next.js compiler for minification. This is 7x faster than Terser.

```js
// next.config.js

module.exports = {
swcMinify: true,
}
```

If you have feedback about `swcMinify`, please share it on the [feedback discussion](https://github.com/vercel/next.js/discussions/30237).

## Unsupported Features

When your application has a `.babelrc` file, Next.js will automatically fall back to using Babel for transforming individual files. This ensures backwards compatibility with existing applications that leverage custom Babel plugins.
Expand Down
9 changes: 9 additions & 0 deletions errors/ignored-compiler-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ignored-compiler-options

#### Why This Error Occurred

Options under the `compiler` key in `next.config.js` only apply to the new Rust based compiler and will be ignored if Babel is used instead. This message will appear if Next.js detects a Babel configuration file while `compiler` options are configured in `next.config.js`

### Useful Links

- [Next.js Compiler](https://nextjs.org/docs/advanced-features/compiler)
Loading