sysgears/webpack-virtual-modules
소개
Webpack Virtual Modules는 메모리에서 파일을 만들고 수정하거나 삭제할 수 있는 webpack 플러그인입니다. webpack은 이 파일들을 파일 시스템에 실제로 존재하는 것처럼 처리합니다.
시스템 및 인프라측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalWebpack Virtual Modules
Webpack Virtual Modules is a plugin that allows for dynamical generation of in-memory virtual modules for JavaScript builds created with webpack. When virtual module is created all the parent virtual dirs that lead to the module filename are created too. This plugin supports watch mode meaning any write to a virtual module is seen by webpack as if a real file stored on disk has changed.
Installation
Use NPM or Yarn to install Webpack Virtual Modules as a development dependency:
# with NPM
npm install webpack-virtual-modules --save-dev
# with Yarn
yarn add webpack-virtual-modules --dev
Usage
You can use Webpack Virtual Modules with webpack 5, 4 and 3. The examples below show the usage with webpack 5 or 4. If you want to use our plugin with webpack 3, check out a dedicated doc:
Generating static virtual modules
Require the plugin in the webpack configuration file, then create and add virtual modules in the plugins array in the
webpack configuration object:
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
]
};
You can now import your virtual modules anywhere in the application and use them:
var moduleFoo = require('module-foo');
// You can now use moduleFoo
console.log(moduleFoo.foo);
Generating dynamic virtual modules
You can generate virtual modules dynamically with Webpack Virtual Modules.
Here's an example of dynamic generation of a module. All you need to do is create new virtual modules using the plugin
and add them to the plugins array. After that, you need to add a webpack hook. For using hooks, consult webpack
compiler hook documentation.
var webpack = require('webpack');
var VirtualModulesPlugin = require('webpack-virtual-modules');
// Create an empty set of virtual modules
const virtualModules = new VirtualModulesPlugin();
var compiler = webpack({
// ...
plugins: [
virtualModules
]
});
compiler.hooks.compilation.tap('MyPlugin', function(compilation) {
virtualModules.writeModule('node_modules/module-foo.js', '');
});
compiler.watch();
In other module or a Webpack plugin, you can write to the module module-foo whatever you need. After this write,
webpack will "see" that module-foo.js has changed and will restart compilation.
virtualModules.writeModule(
'node_modules/module-foo.js',
'module.exports = { foo: "foo" };'
);
More Examples
- Swagger and JSDoc Example with Webpack 5
- Swagger and JSDoc Example with Webpack 4
- Swagger and JSDoc Example with Webpack 3
API Reference
Inspiration
This project is inspired by virtual-module-webpack-plugin.
Contributing
This project uses nari package manager to have reproducible builds without resorting to lockfiles, it uses lockTime field in package.json instead.
To install nari execute:
npm i -g nari
And then nari to install the project.
To run project scripts use nari script_name, for example nari test to run unit tests.
License
Copyright © 2017 SysGears (Cyprus) Limited. This source code is licensed under the MIT license.
관련 프로젝트 살펴보기
불러오는 중…