1.0.1 • Published 3 years ago

vite-plugin-replace-module v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

vite-plugin-replace-module

Vite plugin for modifying imported modules.

Installation

NPM

npm i -D vite-plugin-replace-module

YARN

yarn add -D vite-plugin-replace-module

Usage

vite.config.js
import VitePluginReplaceModule from "vite-plugin-replace-module";

export default {
  plugins: [
    VitePluginReplaceModule({
      rules: [
        {
          originModule: "npm-a",
          replaceModule: "npm-b",
        },
        {
          originModule: "npm-b",
          replaceModule: "npm-c",
          context: /node_modules\/npm-a/,
        },
      ],
    }),
  ],
}

Options

rules[].context

Type: RegExp | (context: String) => booleans

context is RegExp or function, which used to determinate which modules should be modified.

RegExp will be applied to full module path (based on userRequest).

rule[].originModule

Type: String

The module before the replacement.

rule[]replaceModule

Type: String

The module after the replacement.