0.1.0 • Published 8 months ago

bun-plugin-virtual v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

bun-plugin-virtual

Virtual modules plugin for Bun.

Installation

bun add bun-plugin-virtual -d

Bundler usage

import virtual from "bun-plugin-virtual";

Bun.build({
  // other config
  plugins: [
    virtual({
      // An extension is required. You can use any extension you want.
      'batman.js': `export default 'na na na na na'`,
      'src/robin.mjs': `export const robin = 'batmannnnn'`,
      'config.js': {
        hello: 'world'
      }
    })
  ],
});

In your sources you can now import the virtual modules

import batman from 'batman.js'
import { robin } from 'src/robin.mjs'
import { hello } from 'config.js'

console.log(batman) // na na na na na
console.log(robin) // batmannnnn
console.log(hello) // world

The contents of the virtual module will be inlined into your bundle.

Runtime usage

To use as a runtime plugin, create a file that registers the plugin:

// virtual.ts
import virtual from 'bun-plugin-virtual'

Bun.plugin(virtual({}));

Then preload it in your bunfig.toml:

preload = ['./virtual.ts']

Inspired by @rollup/plugin-virtual.

License

MIT

0.1.0

8 months ago