extract-di-webpack-plugin
v5.0.1
Published
Webpack plugin for static dependency injection analysis
Downloads
3
Readme
extract-di-webpack-plugin
Installation
npm i -S extract-di-webpack-plugin
Usage:
Step 1
Add plugin to webpack config:
// webpack.config.js
const ExtractDIPlugin = require('extract-di-webpack-plugin');
module.exports = {
// ...
plugins: [
// ...
new ExtractDIPlugin()
]
}
ExtractDIPlugin accepts 2 arguments:
/**
* @param {string} [moduleName = 'di-definitions] - used for requiring definitions in your code
* @param {{}} options
* @param {string} [options.exportName = '__diDefinitions'] - used for parsing definitions from your modules
*/
Step 2
In your modules use following syntax to export definitions:
// module.js
Object.defineProperty(exports, '__diDefinitions', {
currentUser: ['User', {
request: 'Requst'
}]
});
Exported definitions from all modules will be merged into one object and available for requiring from any place of a code.
Note, it is not necessary to write such definitions manually. Consider using babel-plugin-extract-dependency-definitions to export definitions automatically.
Step 3
Now you can require parsed definitions anywhere you want.
// entry.js
const definitions = require('di-definitons');