# vmodule-webpack-plugin

> A virtual module webpack plug-in

Latest version **2.0.5** (published 2021-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install vmodule-webpack-plugin
pnpm add vmodule-webpack-plugin
yarn add vmodule-webpack-plugin
bun add vmodule-webpack-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2021-01-28 |
| First published | 2017-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Houfeng |
| Maintainers | houzhanfeng |
| Keywords | webpack, plugin, virtual, module |

## Links

- npm: https://www.npmjs.com/package/vmodule-webpack-plugin
- npm.io page: https://npm.io/package/vmodule-webpack-plugin

## Dependencies (4)

- [md5](https://npm.io/package/md5.md) ^2.3.0
- [ntils](https://npm.io/package/ntils.md) ^5.2.0
- [tslib](https://npm.io/package/tslib.md) ^2.0.3
- [chokidar](https://npm.io/package/chokidar.md) ^3.4.3

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 2.0.5 (latest) — 2021-01-28
- 2.0.4 — 2020-12-30
- 2.0.3 — 2020-12-30
- 2.0.2 — 2020-12-30
- 2.0.1 — 2020-12-28
- 1.0.9 — 2018-08-27
- 1.0.8 — 2017-10-19
- 1.0.7 — 2017-10-18
- 1.0.5 — 2017-10-09
- 1.0.4 — 2017-09-21
- 1.0.3 — 2017-09-21
- 1.0.2 — 2017-09-21
- 1.0.1 — 2017-07-27
- 1.0.0 — 2017-07-24

## README

# VModule webpack plugin

VModule 是一个用于创建虚拟模块 webpack 插件。

大约有如下使用场景:
- 需要在构建阶段将动态计算后结果生成一个模块
- 构建后的运行时代码需要引用一些构建阶段的环境变量或其它数据

## 安装

```sh
$ npm i vmodule-webpack-plugin --save
```

## 使用

在 webpack.config.js 中配置 VModule 
```js
const webpack = require('webpack');
const VModulePlugin = require('vmodule-webapck-plugin');

module.exports = {
  ...
  plugins: [
    //返回对象的虚拟模块
    new VModulePlugin({
      name: 'demo-module1',
      handler: function() {
        return { name: 'demo', env: process.env.NODE_ENV };
      },
      //在 watch 的文件发生变化时，重新执行 handler 生成虚拟模块
      watch: ['glob 语法'] 
    }),
    //返回代码的虚拟模块
    new VModulePlugin({
      name: 'demo-module2',
      type: 'js'
      handler: function() {
        reutrn `
          exports.say = function(text) {
            console.log('say:', text);
          };
        `;
      }
    })
  ]
  ...
};
```

在代码中使用虚拟模块
```js
const module1 = require('demo-module1');
const module2 = requrie('demo-module2');

module2.say(JSON.stringify(module1));

//打印
//say: { "name": "demo", "env": "NODE_ENV 的值" }

```

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