Mimics a webpack config's filename extensions, aliases, and loaders inside of the current node process.
You might want to
- instead of bundling your specs with webpack.
- before using linter rules like
- when performing universal rendering with code you also plan to bundle with webpack.
npm install mimic-webpack
In your entry file:
var Mimic = ;webpackConfig: // pass your webpack config hereresolve:extensions: '.foo'alias:myModule: 'theirModule'module:loaders:test: /\.foo$/loader: 'foo-loader';
// code to be processed with foo-loader
Now, anywhere in your project, you can do this:
In the above example:
theirModuleis aliased to
.fooextension is inferred due to `resolve.extensions.
- The module is processed with
requirein the current node process to behave according to the webpack config specified by
options.webpackConfigpassed to the constructor. Returns the current instance.
Mimic.prototype.uninstall- un-does what
Mimic.prototype.installdid. Returns the current instance.
Mimic.restore- restores configuration to the way it was before Mimic was required in.
Paths that were resolved using custom properties in
require.extensions will continue to resolve the same even after
Mimic.prototype.uninstall have been called.
myMimic;require; // still resolves to myModule.foo.
- Loaders must be specified in the webpack config. Loaders specified on the require path will not work
uninstallcan only be run once per instance.