rstackjs/rspack-plugin-virtual-module

An Rspack plugin that allows you to create virtual modules.

45

stars

36

commits

TypeScript

primary language

Apr 27, 2026

updated

plugins
rspack
webpack
Browse cluster: TypeScript/JavaScript bundlers and build tools β†’

README

rspack-plugin-virtual-module

An Rspack plugin that allows you to create virtual modules.

[!WARNING] This plugin is no longer maintained as Rspack v1.5 now provides a built-in VirtualModulesPlugin with better performance. Please use the built-in plugin instead of this one.

npm version license

Installation

# npm
npm install rspack-plugin-virtual-module

# yarn
yarn add rspack-plugin-virtual-module

# pnpm
pnpm add rspack-plugin-virtual-module

Usage

// rspack.config.js
const { RspackVirtualModulePlugin } = require("rspack-plugin-virtual-module");

module.exports = {
  plugins: [
    new RspackVirtualModulePlugin({
      contents: 'export default "Hello World";',
    }),
  ],
};

Then you can import the virtual module in your code:

import hello from "contents";

console.log(hello); // "Hello World"

If you want to dynamically write the contents of the virtual module, you can use the writeModule method:

// rspack.config.js
const { RspackVirtualModulePlugin } = require("rspack-plugin-virtual-module");

const vmp = new RspackVirtualModulePlugin({
  contents: 'export default "Hello World";',
});

// Write the contents of the virtual module after 1 second
setTimeout(() => {
  vmp.writeModule('export default "Hello World 2";');
}, 1000);

module.exports = {
  plugins: [vmp],
};

License

MIT.

Contributors

renovate[bot]

16 commits

chenjiahan

9 commits

sanyuan0704

5 commits

bvanjoi

2 commits

rstackjs/rspack-plugin-virtual-module

An Rspack plugin that allows you to create virtual modules.

45

stars

36

commits

TypeScript

primary language

Apr 27, 2026

updated

plugins
rspack
webpack
Browse cluster: TypeScript/JavaScript bundlers and build tools β†’

README

rspack-plugin-virtual-module

An Rspack plugin that allows you to create virtual modules.

[!WARNING] This plugin is no longer maintained as Rspack v1.5 now provides a built-in VirtualModulesPlugin with better performance. Please use the built-in plugin instead of this one.

npm version license

Installation

# npm
npm install rspack-plugin-virtual-module

# yarn
yarn add rspack-plugin-virtual-module

# pnpm
pnpm add rspack-plugin-virtual-module

Usage

// rspack.config.js
const { RspackVirtualModulePlugin } = require("rspack-plugin-virtual-module");

module.exports = {
  plugins: [
    new RspackVirtualModulePlugin({
      contents: 'export default "Hello World";',
    }),
  ],
};

Then you can import the virtual module in your code:

import hello from "contents";

console.log(hello); // "Hello World"

If you want to dynamically write the contents of the virtual module, you can use the writeModule method:

// rspack.config.js
const { RspackVirtualModulePlugin } = require("rspack-plugin-virtual-module");

const vmp = new RspackVirtualModulePlugin({
  contents: 'export default "Hello World";',
});

// Write the contents of the virtual module after 1 second
setTimeout(() => {
  vmp.writeModule('export default "Hello World 2";');
}, 1000);

module.exports = {
  plugins: [vmp],
};

License

MIT.

Contributors

renovate[bot]

16 commits

chenjiahan

9 commits

sanyuan0704

5 commits

bvanjoi

2 commits

Languages

TypeScript

36.5%

JavaScript

33.4%

CSS

26.6%

HTML

3.5%