Usage with Next.js v12 and SWC as the compiler
See original GitHub issueHi, I’d like to ask what is the correct way to use graphql-let
with Next.js v12, more specifically with SWC though.
What I’ve done:
- I had
babel.config.js
file at first - I ran
yarn build
- I was told by next.js that SWC is not used because of recognized babel config - I removed
babel.config.js
- I changed
jest.config.js
as suggested here - https://github.com/vercel/next.js/issues/30811#issuecomment-963102661 - I ran
yarn build
again - This time, no warning from next.js build, so I guess SWC is used.
What I’m worried about:
My current next.config.js
looks somewhat like this:
module.exports = {
i18n,
pageExtensions: ["page.tsx"],
webpack(config, options) {
// taken from: https://github.com/vercel/next.js/blob/canary/examples/with-typescript-graphql/next.config.js
config.module.rules.push(
{
test: /\.graphql$/u,
exclude: /node_modules/u,
use: [options.defaultLoaders.babel, { loader: "graphql-let/loader" }],
},
{
test: /\.graphqls$/u,
exclude: /node_modules/u,
use: ["graphql-let/schema/loader"],
},
)
return config
},
}
I see the options.defaultLoaders.babel
entry (it is { loader: 'babel-loader', options: { presets: ['@babel/preset-typescript', '@babel/preset-react'] } }
entry in the graphql-let
docs), and I also believe graphql-let/loader
is using babel.
The question is:
Does it mean both SWC and Babel fire up when compiling the code? Does Babel jump in only to take care of .graphqls?
files, no it is OK in terms of performance? Is the next step in getting rid of Babel (and towards better performance) for this library to create an SWC-based transformer?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
Advanced Features: Next.js Compiler
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...
Read more >Why You Should Replace Babel with SWC in Next.js
Babel was one of the most widely used compilers for Next.js. However, Babel is driven out of use with Next.js v12's robust SWC...
Read more >How I change my compiler from BABEL to SWC in NextJS ...
The problem here is that you are using a Babel plugin for something that can be done through Next.js config: inlining the SVG....
Read more >Customize antd in Next.js with SWC - Medium
Next.JS introduced its own compiler, (after v12.0.0) written in Rust using SWC, which allows Next.js to transform and minify your JavaScript code for ......
Read more >What's new in Next.js 12 - LogRocket Blog
One of the key features of Next 12 is performance optimization. To boost performance, Next.js replaced the Babel compiler with an extensible ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll continue with a related topic, which is the integration with Jest. I think I figured this one out, so I want to share my Jest config here to help anybody who struggles with it. I’m using the new
next/jest
package to bootstrap the config, but I still need to override something:For SWC, the important things are:
next/jest
automatically adds SWC as the compiler for js/ts/jsx/tsx (intransform
)transform:
, for.graphql
files, thesubsequentTransformer
needs to be defined to use next’s internal SWC Jest transformer@tettoffensive Hi, I can provide no update on this.