esbuild-virtual
v1.0.1
Published
Load module from memory
Downloads
2
Readme
Esbuild virtual plugin
Load module from memory
Install
pnpm install -D esbuild-virtual
yarn add -D esbuild-virtual
npm install -D esbuild-virtual
Import
// esm
import virtual from 'esbuild-virtual';
// commonjs
const { default: virtual } = require('esbuild-virtual');
Usage
// simple
virtual({
modules: [
{
filter: /^MODULE_NAME$/,
result: `export default {};`,
},
]
})
// specify loader
virtual({
modules: [
{
filter: /^MODULE_NAME$/,
result: () => ({
contents: `export default {};`,
loader: 'ts'
}),
},
]
})
Options
interface Options {
modules: Module[];
}
interface Module {
// match import
filter: RegExp;
// see https://esbuild.github.io/plugins/#on-load-results
result: string | (() => Promise<Partial<OnLoadResult>>);
}