Like Webpack's require
English | 简体中文
✅ dynamic-require similar to 👉 Webpack require('./foo/' + bar)
📦 Out of the box
🔨 Work only in the vite serve
phase
npm i vite-require -D
import { viteRequire } from 'vite-require'
export default {
plugins: [
viteRequire(/* options */)
]
}
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
}
}