Skip to content

Commit

Permalink
Add swcMinifyDebugOptions (#37172)
Browse files Browse the repository at this point in the history
This also updates swc crates to swc-project/swc@7eac561

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
  • Loading branch information
kdy1 and ijjk committed May 29, 2022
1 parent c7ab218 commit 748ce12
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 19 deletions.
23 changes: 23 additions & 0 deletions docs/advanced-features/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,29 @@ module.exports = {

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

### Minifier debug options

While the minifier is experimental, we are making the following options available for debugging purposes. They will not be available once the minifier is made stable.

```js
// next.config.js

module.exports = {
experimental: {
swcMinifyDebugOptions: {
compress: {
defaults: true,
side_effects: false,
},
},
},
swcMinify: true,
}
```

If your app works with the options above, it means `side_effects` is the problematic option.
See [the SWC documentation](https://swc.rs/docs/configuration/minification#jscminifycompress) for detailed options.

### Modularize Imports

Allows to modularize imports, similar to [babel-plugin-transform-imports](https://www.npmjs.com/package/babel-plugin-transform-imports).
Expand Down
25 changes: 13 additions & 12 deletions packages/next-swc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/next-swc/crates/emotion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "AST Transforms for emotion"
license = "Apache-2.0"
name = "swc_emotion"
repository = "https://github.com/vercel/next.js.git"
version = "0.5.0"
version = "0.7.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/modularize_imports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2018"
license = "Apache-2.0"
name = "modularize_imports"
repository = "https://github.com/vercel/next.js.git"
version = "0.4.0"
version = "0.6.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ swc_bundler = { version = "0.147.0", features = ["concurrent"] }
swc_common = { version = "0.18.7", features = ["concurrent", "sourcemap"] }
swc_ecma_loader = { version = "0.30.2", features = ["node", "lru"] }
swc_ecmascript = { version = "0.157.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_plugin_runner = { version = "0.55.0", optional = true, default-features = false }
swc_node_base = "0.5.3"
swc_plugin_runner = { version = "0.55.0",optional=true }
swc_node_base = "0.5.5"
tracing = { version = "0.1.32", features = ["release_max_level_info"] }
tracing-futures = "0.2.5"
tracing-subscriber = "0.3.9"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/styled_components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "styled_components"
repository = "https://github.com/vercel/next.js.git"
version = "0.29.0"
version = "0.31.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/styled_jsx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2018"
license = "Apache-2.0"
name = "styled_jsx"
repository = "https://github.com/vercel/next.js.git"
version = "0.4.0"
version = "0.6.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
12 changes: 11 additions & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,17 @@ export default async function getBaseWebpackConfig(
cacheDir: path.join(distDir, 'cache', 'next-minifier'),
parallel: config.experimental.cpus,
swcMinify: config.swcMinify,
terserOptions,
terserOptions: {
...terserOptions,
compress: {
...terserOptions.compress,
...(config.experimental.swcMinifyDebugOptions?.compress ?? {}),
},
mangle: {
...terserOptions.mangle,
...(config.experimental.swcMinifyDebugOptions?.mangle ?? {}),
},
},
}).apply(compiler)
},
// Minify CSS
Expand Down
11 changes: 11 additions & 0 deletions packages/next/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ export interface ExperimentalConfig {
>
swcTraceProfiling?: boolean
forceSwcTransforms?: boolean

/**
* The option for the minifier of [SWC compiler](https://swc.rs).
* This option is only for debugging the SWC minifier, and will be removed once the SWC minifier is stable.
*
* @see [SWC Minification](https://nextjs.org/docs/advanced-features/compiler#minification)
*/
swcMinifyDebugOptions?: {
compress?: object
mangle?: object
}
swcPlugins?: Array<[string, Record<string, unknown>]>
largePageDataBytes?: number
}
Expand Down
6 changes: 6 additions & 0 deletions packages/next/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@ function assignDefaults(userConfig: { [key: string]: any }) {
)
}

if (result.experimental?.swcMinifyDebugOptions) {
Log.warn(
'SWC minify debug option specified. This option is for debugging minifier issues and will be removed once SWC minifier is stable.'
)
}

if (
result.experimental?.outputFileTracingRoot &&
!isAbsolute(result.experimental.outputFileTracingRoot)
Expand Down

0 comments on commit 748ce12

Please sign in to comment.