🌜
ğŸŒž
@rollup/plugin-virtual

@rollup/plugin-virtual

v2.1.0

Load virtual modules from memory

npm install @rollup/plugin-virtual

README

npm size libera manifesto

@rollup/plugin-virtual

🍣 A Rollup plugin which loads virtual modules from memory.

Requirements

This plugin requires an LTS Node version (v8.0.0+) and Rollup v1.20.0+.

Install

Using npm:

npm install @rollup/plugin-virtual --save-dev

Usage

Note. Use this plugin before any others such as node-resolve or commonjs, so they do not alter the output.

Suppose an entry file containing the snippet below exists at src/entry.js, and attempts to load batman and src/robin.js from memory:

// src/entry.js
import batman from 'batman';
import robin from './robin.js';

console.log(batman, robin);

Create a rollup.config.js configuration file and import the plugin:

import virtual from '@rollup/plugin-virtual';

export default {
  input: 'src/entry.js',
  // ...
  plugins: [
    virtual({
      batman: `export default 'na na na na na'`,
      'src/robin.js': `export default 'batmannnnn'`
    })
  ]
};

Then call rollup either via the CLI or the API.

Options

This plugin has no formal options. The lone parameter for this plugin is an Object containing properties that correspond to a String containing the virtual module's code.

Using the Plugin for Bundle Input

It's possible to use the plugin to specify an entry point for a bundle. To do so, implement a pattern simple to what is shown below:

import virtual from '@rollup/plugin-virtual';

export default {
  input: 'entry',
  // ...
  plugins: [
    virtual({
      entry: `
import batman from 'batcave';
console.log(batman);
`
    })
  ]
};

License

MIT

General

License
MIT
Typescript Types
Built-in
Tree-shakeable
Yes

Popularity

GitHub Stargazers
2,785
Community Interest
2,425
Number of Forks
446

Maintenance

Commits
10/219/22050
Last Commit
Open Issues
25
Closed Issues
710
Open Pull Requests
17
Closed Pull Requests
115

Versions

Versions Released
10/219/2201
Latest Version Released
Feb 22, 2022
Current Tags
latest2.1.0

Dependencies

Dependencies (0)
Dev Dependencies (2)

Contributors

shellscape
shellscape
Commits: 350
lukastaegert
lukastaegert
Commits: 40
NotWoods
NotWoods
Commits: 39
benmccann
benmccann
Commits: 19
danielgindi
danielgindi
Commits: 14
tjenkinson
tjenkinson
Commits: 14
LarsDenBakker
LarsDenBakker
Commits: 13
Andarist
Andarist
Commits: 8
guybedford
guybedford
Commits: 7
TrySound
TrySound
Commits: 7
chengcyber
chengcyber
Commits: 4
eight04
eight04
Commits: 3
wesleygrimes
wesleygrimes
Commits: 3
pnevares
pnevares
Commits: 3
Kocal
Kocal
Commits: 3