vite-plugin-isomorphic-import

1.0.0 • Public • Published

vite-plugin-isomorphic-import

A vite plugin that allows you to configure whether to import modules on the server-side or client-side.

Install

npm i -D vite-plugin-isomorphic-import

or

yarn add -D vite-plugin-isomorphic-import

Usage

// vite.config.js
import { isomorphicImport } from 'vite-plugin-isomorphic-import';

export default {
	plugins: [
		isomorphicImport({
			// modules that you want to be imported only on client-side
			client: ['some-client-side-module'],
			// modules that you want to be imported only on server-side
			server: [],
		})
	]
}

This will be very useful for handling browser-only modules that do not support for node.

Effect

// ... other imports
import someModule from 'some-client-side-module';
// ... other imports

This statement will be removed when on server-side:

// ... other imports

Therefore, it should be noted that if you use the variable someModule on the server-side, an error(undefined) will be occured.

/vite-plugin-isomorphic-import/

    Package Sidebar

    Install

    npm i vite-plugin-isomorphic-import

    Weekly Downloads

    8

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    6.38 kB

    Total Files

    6

    Last publish

    Collaborators

    • lyzs