GithubHelp home page GithubHelp logo

react18-tools / esbuild-react18-useclient Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 68 KB

esbuild plugin for compiling libraries compatible with React 18 server and client component, Nextjs13, Remix, etc. Please use Turborepo Template -> https://github.com/react18-tools/turborepo-template

Home Page: https://github.com/react18-tools/turborepo-template

License: MIT License

JavaScript 47.61% TypeScript 52.39%
esbuild esbuild-plugin javascript nextjs nodejs react-libraries react-server-components react18 reactjs tsup

esbuild-react18-useclient's Introduction

esbuild-react18-useclient Version Downloads Publish to npm and GitHub

This package is deprecated in favor of esbuild-plugin-react18 Please switch to esbuild-plugin-react18, which also offers additional options and more control over your build output.

Build Awesome Libraries using React Server Components and make your Mark!

This is an esbuild plugin for compiling libraries compatible with React 18 server and client component, Nextjs13, Remix, etc.

Why?

✅ Unleash the power of combining react client and server components in your libraries ✅ Full TypeScript support out of the box ✅ Simple and tiny ✅ Easy to use — just add the plugin, and you are good to go

Introduction of React server components in React 18 has unlocked immense possibilities. However, library authors are not yet able to fully encash upon this potential. Many libraries, like chakra-ui, simply add “use client” for each component. However, much more can be unleashed when we can use both server and client components to build libraries. Also check-out this blog.

Example

Checkout https://github.com/mayank1513/nextjs-themes

Compatibility

  • JavaScript/TypeScript React libraries using tsup or other builders based on esbuild

This plugin seamlessly integrates with tsup and any other builders based on esbuild. With this you can have both server and client components in your library and the plugin will take care of the rest. All you need to do is add this plugin and add "use client"; on top of client components (in your source code).

Add dependencies:

yarn add --dev esbuild-react18-useclient

or

pnpm add -D esbuild-react18-useclient

or

npm install -D esbuild-react18-useclient

If you are using monorepo or workspaces you can install this plugin to root using -w or to specific workspace using --filter your-package or --scope your-package for pnpm and yarn workspaces respectively.

Use with tsup

// tsup.config.ts or tsup.config.js
import { defineConfig } from "tsup";
import reactUseClient from "esbuild-react18-useclient";

export default defineConfig(options => ({
    ...
    esbuildPlugins:[reactUseClient]
}));

License

Licensed as MIT open source.


with 💖 by Mayank Kumar Chaudhari

esbuild-react18-useclient's People

Contributors

mayank1513 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

esbuild-react18-useclient's Issues

IDE showing type error

IDE showing following error

Argument of type '(options: Options) => { format: ("cjs" | "esm")[]; target: "es2019"; sourcemap: true; clean: true; minify: boolean; plugins: typeof import("C:/Users/G/web/open-source/nextjs-themes/node_modules/.pnpm/[email protected]/node_modules/esbuild-react18-useclient/index")[]; }' is not assignable to parameter of type 'Options | Options[] | ((overrideOptions: Options) => MaybePromise<Options | Options[]>)'.
  Type '(options: Options) => { format: ("cjs" | "esm")[]; target: "es2019"; sourcemap: true; clean: true; minify: boolean; plugins: typeof import("C:/Users/G/web/open-source/nextjs-themes/node_modules/.pnpm/[email protected]/node_modules/esbuild-react18-useclient/index")[]; }' is not assignable to type '(overrideOptions: Options) => MaybePromise<Options | Options[]>'.
    Type '{ format: ("cjs" | "esm")[]; target: "es2019"; sourcemap: true; clean: true; minify: boolean; plugins: (typeof reactUseClientPlugin)[]; }' is not assignable to type 'MaybePromise<Options | Options[]>'.
      Type '{ format: ("cjs" | "esm")[]; target: "es2019"; sourcemap: true; clean: true; minify: boolean; plugins: (typeof reactUseClientPlugin)[]; }' is not assignable to type 'Options'.
        Types of property 'plugins' are incompatible.
          Type 'typeof import("C:/Users/G/web/open-source/nextjs-themes/node_modules/.pnpm/[email protected]/node_modules/esbuild-react18-useclient/index")[]' is not assignable to type 'Plugin[]'.
            Property 'name' is missing in type 'typeof import("C:/Users/G/web/open-source/nextjs-themes/node_modules/.pnpm/[email protected]/node_modules/esbuild-react18-useclient/index")' but required in type 'Plugin'.ts(2345)
index.d.ts(41, 5): 'name' is declared here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.