Webpack Virtual Modules
Webpack Plugin that allows dynamical generation of in-memory virtual modules. Watch mode is supported. Any write to virtual module will be seen by Webpack as if the corresponding file was changed.
Installation
npm install --save-dev webpack-virtual-modulesUsage
Static virtual modules generation
Sample Webpack config:
var VirtualModulesPlugin = require("webpack-virtual-modules");
var virtualModules = new VirtualModulesPlugin({
'node_modules/module-foo.js': 'module.exports = { foo: "foo" };'
'node_modules/module-bar.js': 'module.exports = { bar: "bar" };'
});
module.exports = {
// ...
plugins: [
virtualModules
]
};Somewhere in the source code:
var moduleFoo = require('module-foo');
// Outputs 'foo'
console.log(moduleFoo.foo);Dynamic virtual modules generation
var webpack = require("webpack");
var VirtualModulesPlugin = require("webpack-virtual-modules");
var virtualModules = new VirtualModulesPlugin();
var compiler = webpack({
// ...
plugins: [
virtualModules
]
});
compiler.plugin('watch', function(callback) {
virtualModules.writeModule('node_modules/module-foo.js', '');
callback();
});
compiler.watch();// Later in some other code, perhaps in other Webpack plugin:
virtualModules.writeModule('node_modules/module-foo.js',
'module.exports = { foo: "foo" };');
// After this write the webpack will "see" that module-foo.js
// has been changed and restarts compilationInspiration
This project is inspired by: https://github.com/rmarscher/virtual-module-webpack-plugin
License
Copyright © 2017 SysGears INC. This source code is licensed under the MIT license.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
