8000 GitHub - coder-xiaotian/swc-useclient at 3e9ec2167a359672595b05f24cf84897ffeddd8e
[go: up one dir, main page]

Skip to content

A swc plugin that automatically converts React component libraries into "React Client Component". For example, you can automatically convert components from @mui into "React Client Component" without having to wrap a component that uses "use client".

License

Notifications You must be signed in to change notification settings

coder-xiaotian/swc-useclient

Repository files navigation

use-client

中文

NPM npm Rust

A swc plugin that automatically converts React component libraries into "React Client Component". For example, you can automatically convert components from @mui into "React Client Component" without having to wrap a component that uses "use client".

Installation

npm:

npm install -D use-client

yarn:

yarn add -D use-client

pnpm:

pnpm i -D use-client

Configuration

  • include:["ui-library-path"]

Examples

next.js configuration:

const nextConfig = {
  experimental: {
    swcPlugins: [
      [
        "use-client",
        {
          include: ["@mui/material", "@mui/icons-material""antd", "@ant-design/icons"],
        },
      ],
    ],
  },
};

swc configuration:

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "experimental": {
      "plugins": [
        ["use-client", {
          "include": ["@mui/material", "@mui/icons-material""antd", "@ant-design/icons"]
        }]
      ]
    }
  }
}

FAQ

  • The swc plugin interrupts tree shaking

At present, this is an expected behavior, The Next.js team will improve it in the future。You can temporarily solve this problem by configuring modularizeImports:

const nextConfig = {
  modularizeImports: {
    "@mui/material": {
      transform: "@mui/material/{{member}}"
    },
  },
  experimental: {
    swcPlugins: [
      [
        "use-client",
        {
          include: ["@mui/material"],
        },
      ],
    ],
  },
};

Note that some functions do not follow the '@ mui/material/{{member}}' rule, such as createTheme and ThemeProvider, which need to be processed separately as' import {createTheme, ThemeProvider} from '@ mui/material/styles'`

🌟🌟🌟🌟 If this plugin is helpful to you, give the author a star.🙏🙏🙏🌟🌟🌟🌟

About

A swc plugin that automatically converts React component libraries into "React Client Component". For example, you can automatically convert components from @mui into "React Client Component" without having to wrap a component that uses "use client".

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0