@rollup/plugin-virtual
Load virtual modules from memory
Last updated 5 years ago by shellscape .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @rollup/plugin-virtual 
SYNC missed versions from official npm registry.

npm size libera manifesto

@rollup/plugin-virtual

🍣 A Rollup plugin which loads virtual modules from memory.

Requirements

This plugin requires an LTS Node version (v14.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

Current Tags

  • 3.0.2                                ...           latest (a year ago)

8 Versions

  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.3                                ...           5 years ago
  • 2.0.2                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE