auto-require-webpack-plugin
Webpack plugin to automatically require the module itself, if module name defined. For Example:
{ iftypeof exports === 'object' && typeof module === 'object' moduleexports = ; else iftypeof define === 'function' && defineamd ; else iftypeof exports === 'object' exports"common/view" = ; else root"common/view" = ;}this { /* Module code here */}; // When using require, call the module automaticallytypeof define === 'function' && defineamd && ;
Usage
new AutoRequirePlugin(options)
/* Use constructor options directly */var options = true; moduleexports = plugins: options ;
Or
/* Use `output.autoRequire` to set options */var options = true; moduleexports = output: autoRequire: options plugins: ;
There are two ways to configure AutoRequirePlugin: constructor's parameter or output.autoRequire
. The latter will override constructor's parameter.
Examples
Type of options
can be boolean
, string
, RegExp
, function
and Array
.
Require all modules
moduleexports = plugins: true ;
Require module with specific name
moduleexports = plugins: 'common/view' ;
Require module(s) matching regular expression
moduleexports = plugins: /^common/ ;
Require module(s) testing by function
moduleexports = plugins: { return moduleNamelength > 2; } ;
More complex case
moduleexports = plugins: /^pages\/.+/ { return moduleName >= 0 && moduleName < 0; } ;