1. rspack-plugin-virtual-module
A plugin for rspack that allows you to create virtual modules.
rspack-plugin-virtual-module
Package: rspack-plugin-virtual-module
Last modified: Thu, 07 Sep 2023 11:16:10 GMT
Version: 0.1.12
License: MIT
Downloads: 9,073

Install

npm install rspack-plugin-virtual-module
yarn add rspack-plugin-virtual-module

rspack-plugin-virtual-module

A plugin for rspack that allows you to create virtual modules.

Installation

 # npm
npm install rspack-plugin-virtual-module
# yarn
yarn add rspack-plugin-virtual-module
# pnpm
pnpm add rspack-plugin-virtual-module

Usage

 const { RspackVirtualModulePlugin } = require('rspack-plugin-virtual-module');
// rspack.config.js
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],
};

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code