Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rspack-contrib/rspack-plugin-virtual-module
An Rspack plugin that allows you to create virtual modules.
https://github.com/rspack-contrib/rspack-plugin-virtual-module
plugins rspack webpack
Last synced: 16 days ago
JSON representation
An Rspack plugin that allows you to create virtual modules.
- Host: GitHub
- URL: https://github.com/rspack-contrib/rspack-plugin-virtual-module
- Owner: rspack-contrib
- License: mit
- Created: 2023-03-27T09:44:54.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-01T10:07:32.000Z (25 days ago)
- Last Synced: 2024-12-09T02:07:36.090Z (18 days ago)
- Topics: plugins, rspack, webpack
- Language: TypeScript
- Homepage:
- Size: 353 KB
- Stars: 37
- Watchers: 1
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rspack - rspack-plugin-virtual-module
README
# rspack-plugin-virtual-module
An Rspack plugin that allows you to create virtual modules.
## 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).