Skip to content

Latest commit

 

History

History
executable file
·
65 lines (44 loc) · 1.83 KB

README.md

File metadata and controls

executable file
·
65 lines (44 loc) · 1.83 KB

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/input.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 {
  entry: '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.

License

MIT