ReasonJun

Next.js : Compiler SWC (Speedy Web Compiler) 본문

Frontend/Next.js

Next.js : Compiler SWC (Speedy Web Compiler)

ReasonJun 2023. 6. 20. 18:00
728x90

SWC (Speedy Web Compiler) is a fast JavaScript/TypeScript compiler that is used in Next.js to optimize the build process and improve the performance of Next.js applications. It is a popular alternative to the Babel compiler, known for its impressive speed and compatibility with modern JavaScript and TypeScript syntax.

 

It is made in RUST language based on parallel processing, so it is faster than Javascript based on single thread.

 

* Babel : Transpiler 

* Terser : Minifier(mangle & compress)

 

Next.js leverages SWC as a replacement for Babel during the build step, allowing for faster compilation and transpilation of your code. By using SWC, Next.js aims to reduce build times and enhance the overall developer experience.

 

Here are a few key aspects of SWC in the context of Next.js:

  1. Compilation speed: SWC is designed to be highly performant and significantly faster than Babel in terms of compilation speed. This can lead to shorter build times for Next.js applications, especially in larger projects or when dealing with complex codebases.
  2. Compatibility: SWC supports a wide range of modern JavaScript and TypeScript syntax, including features from ECMAScript 2015 (ES6) up to the latest ECMAScript standards. It ensures that your Next.js application can take advantage of the latest language features without sacrificing performance.
  3. Babel compatibility: While SWC is a different compiler, it aims to maintain compatibility with Babel configurations and plugins. This allows you to reuse your existing Babel configuration with minimal changes when switching to SWC in a Next.js project.

To enable SWC in Next.js, you need to have a Next.js version that includes support for SWC (usually a recent version). Next.js will automatically detect SWC as a dependency and use it during the build process, ensuring that your code is transpiled and optimized with SWC.

 

It's worth noting that while SWC is used by default in Next.js, you can still use Babel in your Next.js project if needed. Next.js provides configuration options to customize the build process and choose between SWC and Babel as the compiler.

 

In summary, SWC is a fast JavaScript/TypeScript compiler utilized by Next.js to improve build performance and enable compatibility with modern language features. It helps reduce build times and enhances the overall development experience in Next.js applications.

 

https://nextjs.org/docs/architecture/nextjs-compiler

 

Architecture: Next.js Compiler | Next.js

The Next.js Compiler, written in Rust using SWC, allows Next.js to transform and minify your JavaScript code for production. This replaces Babel for individual files and Terser for minifying output bundles. Compilation using the Next.js Compiler is 17x fas

nextjs.org

 

728x90

'Frontend > Next.js' 카테고리의 다른 글

Next.js : Dynamic Import (Lazy Loading)  (0) 2023.06.20
Next.js : Draft Mode  (0) 2023.06.20
When is it good to use SSG in next.js?  (0) 2023.06.19
Next.js : <Link> vs <a> (Client-side navigation)  (0) 2023.06.19
Next.js : API Routes  (0) 2023.06.18
Comments