Friday, 30 September 2022

Next.js how to use SWC compiler with Material UI and swc-plugin-transform-import

I've been struggling with transforming imports with Next.js using SWC complier.

I'm trying to make use of swc-plugin-transform-import as a replacement of babel-plugin-transform-imports for shorting on Material UI imports.

As documented, I've tried with this settings. It shows experimental warning, but other than that it ignores plugin all together.

// next.config.js

module.exports = {
  experimental: {
    swcPlugins: [
      [
        'swc-plugin-transform-import',
        {
          "@mui/material": {
            transform: "@mui/material/${member}",
            preventFullImport: true
          },
          "@mui/icons-material": {
            transform: "@mui/icons-material/${member}",
            preventFullImport: true
          },
          "@mui/styles": {
            transform: "@mui/styles/${member}",
            preventFullImport: true
          },
          "@mui/lab": {
            transform: "@mui/lab/${member}",
            preventFullImport: true
          }
        }
      ]
    ]
  }
}

Anyone knows how to enable and configure swc-plugin-transform-import for Next.js? Thank you



from Next.js how to use SWC compiler with Material UI and swc-plugin-transform-import

No comments:

Post a Comment