New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

use-client

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-client

A swc plugin that automatically converts component libraries into "React Client Component".

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
1.1K
23.98%
Maintainers
1
Weekly downloads
 
Created
Source

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

PropertyTypeDescription
include(string | IncludeConfig)[] | Array of paths to be transformed

IncludeConfig:

PropertyTypeDescription
pathstring | Path to match
insertstringCustom content to insert at the beginning of the file, default value: "use client"

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"]
        }]
      ]
    }
  }
}

Custom Insert Content:

const nextConfig = {
  experimental: {
    swcPlugins: [
      [
        'use-client',
        {
          include: ["path/to", {
            path: "path/to",
            insert: "use strict"
          }]
        }
      ],
    ]
  }
}

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.🙏🙏🙏🌟🌟🌟🌟

Keywords

swc

FAQs

Package last updated on 16 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts