Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rollup/plugin-virtual

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rollup/plugin-virtual

Load virtual modules from memory

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
198K
decreased by-3.06%
Maintainers
4
Weekly downloads
 
Created

What is @rollup/plugin-virtual?

@rollup/plugin-virtual is a Rollup plugin that allows you to create virtual modules. These are modules that do not exist as files on disk but are instead created in memory. This can be useful for injecting code, creating mock modules for testing, or dynamically generating content during the build process.

What are @rollup/plugin-virtual's main functionalities?

Creating a virtual module

This feature allows you to create a virtual module named 'my-virtual-module' with the content 'export default "This is virtual!"'. This module can then be imported and used in your Rollup bundle.

const virtual = require('@rollup/plugin-virtual');

module.exports = {
  input: 'src/main.js',
  plugins: [
    virtual({
      'my-virtual-module': 'export default "This is virtual!"'
    })
  ],
  output: {
    file: 'bundle.js',
    format: 'es'
  }
};

Mocking modules for testing

This feature allows you to mock the 'fs' module with a virtual module that provides a custom implementation of the 'readFile' function. This can be useful for testing purposes.

const virtual = require('@rollup/plugin-virtual');

module.exports = {
  input: 'src/main.js',
  plugins: [
    virtual({
      'fs': 'export default { readFile: () => "mocked content" }'
    })
  ],
  output: {
    file: 'bundle.js',
    format: 'es'
  }
};

Dynamically generating content

This feature allows you to create a virtual module with content that is dynamically generated at build time. In this example, the module exports a string with the current date and time.

const virtual = require('@rollup/plugin-virtual');

module.exports = {
  input: 'src/main.js',
  plugins: [
    virtual({
      'dynamic-module': `export default "Generated at ${new Date().toISOString()}"`
    })
  ],
  output: {
    file: 'bundle.js',
    format: 'es'
  }
};

Other packages similar to @rollup/plugin-virtual

Keywords

FAQs

Package last updated on 22 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc