# rspack-plugin-virtual-module

> An Rspack plugin that allows you to create virtual modules.

Latest version **1.0.1** (published 2025-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install rspack-plugin-virtual-module
pnpm add rspack-plugin-virtual-module
yarn add rspack-plugin-virtual-module
bun add rspack-plugin-virtual-module
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2025-05-24 |
| First published | 2023-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Maintainers | chenjiahan, sanyuan0704 |

## Links

- npm: https://www.npmjs.com/package/rspack-plugin-virtual-module
- Repository: https://github.com/rspack-contrib/rspack-plugin-virtual-module
- Homepage: https://github.com/rspack-contrib/rspack-plugin-virtual-module#readme
- Issues: https://github.com/rspack-contrib/rspack-plugin-virtual-module/issues
- npm.io page: https://npm.io/package/rspack-plugin-virtual-module

## Dependencies (1)

- [fs-extra](https://npm.io/package/fs-extra.md) ^11.3.0

## Recent versions

- 1.0.1 (latest) — 2025-05-24
- 1.0.0 — 2025-04-21
- 0.1.13 — 2024-06-12
- 0.1.12 — 2023-09-07
- 0.1.11 — 2023-08-28
- 0.1.10 — 2023-08-16
- 0.1.9 — 2023-08-16
- 0.1.8 — 2023-08-16
- 0.1.7 — 2023-06-20
- 0.1.6 — 2023-06-20
- 0.1.5 — 2023-05-18
- 0.1.4 — 2023-05-17
- 0.1.3 — 2023-05-05
- 0.1.2 — 2023-04-19
- 0.1.1 — 2023-04-19
- … 2 more at https://npm.io/package/rspack-plugin-virtual-module/versions

## README

# rspack-plugin-virtual-module

An Rspack plugin that allows you to create virtual modules.

<p>
  <a href="https://npmjs.com/package/rspack-plugin-virtual-module">
   <img src="https://img.shields.io/npm/v/rspack-plugin-virtual-module?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
  </a>
  <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
</p>

## Installation

```bash
# npm
npm install rspack-plugin-virtual-module

# yarn
yarn add rspack-plugin-virtual-module

# pnpm
pnpm add rspack-plugin-virtual-module
```

## Usage

```js
// 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:

```js
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:

```js
// 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](./LICENSE).

---
_Source: https://npm.io/package/rspack-plugin-virtual-module · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
