vite-plugin / vite-require

Like Webpack's require
MIT License
9 stars 3 forks source link

vite-require

Like Webpack's require

NPM version NPM Downloads

English | 简体中文

✅ dynamic-require similar to 👉 Webpack require('./foo/' + bar)

📦 Out of the box

🔨 Work only in the vite serve phase

Install

npm i vite-require -D

Usage

import { viteRequire } from 'vite-require'
export default {
  plugins: [
    viteRequire(/* options */)
  ]
}

API

viteRequire([options])

export interface Options {
  extensions?: string[]
  filter?: (id: string) => false | void
  dynamic?: {
    /**
     * 1. `true` - Match all possibilities as much as possible, More like `webpack`
     * 2. `false` - It behaves more like `@rollup/plugin-dynamic-import-vars`
     * @default true
     */
    loose?: boolean
  }
}