Skip to content

Framework-agnostic way to mark JavaScript modules as Server or Client only

Notifications You must be signed in to change notification settings

deve-sh/server-and-client-only

Repository files navigation

Framework-agnostic way to mark JavaScript modules as Server or Client only.

Inspired by server-only and client-only.

Note: If you're already using a React framework, there's no need of using this package, just use server-only or client-only as indicated here: Rendering: Composition Patterns | Next.js - Keeping Server-only Code out of the Client Environment

Usage

npm install server-only-module
# or
npm install client-only-module

Use it in your modules:

import 'server-only-module';

// or

import 'client-only-module';

async function yourCode() {
    ...
}

Running Tests

npm run test

Publishing to npm

# Don't forget to bump the version first

npm run release:server-only
npm run release:client-only

Minor Note

This package uses Node.js' Conditional Exports, hence the minimum required Node version is 12.

About

Framework-agnostic way to mark JavaScript modules as Server or Client only

Resources

Stars

Watchers

Forks