Package Exports
- webpack-virtual-modules
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (webpack-virtual-modules) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Webpack Virtual Modules
Webpack Plugin that allows dynamical generation of in-memory virtual modules.
Installation
npm install --save-dev webpack-virtual-modules
Usage
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 writre the webpack will "see" that module-foo.js
// has been changed and restarts compilation
Inspiration
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.