Modification of proxyquire to work with webpack aliases. Proxies commonjs require/es6 import in order to allow overriding dependencies during testing. Just hides some webpack magic inside.
;;// optionalproxyquire;// you can use webpack-aliased filenames both as module name and stub name.
Now, at last, you can use aliases as names of deps to be mocked. So you can use old proxyquire in more modern way.
the other way:
If you prefer using original proxyquire - have a look in resolveQuire. It is pure functional sugar around it, and enables same features as proxyquire-webpack-alias.
proxyquire - 2
This library uses proxyquire-2, a bit more powerfull fork of original one.
For details about
proxyquire-2 API – see proxyquire documentation.
It is just extends functionality, 100% compatible with old one.
configire(webpack.alias.conf)allows you to overwrite location of webpack.aliases configuration file. By default one will try to find 'webpack.config.js' or 'webpack.config.babel.js' in project root.
defaultExport- functional class, similar to Proxyquire.
Alias behavior similar to babel-plugin-webpack-alias.
As long we
take some sources from it.
So you have one file. You use webpack alises and address other files using them.
And then you want to mock deps with
But you cant.
You have to mock relative imports. And each time you have to
guess the right name.
const mocked =
So, this lets fix this issue.
//import proxyquire from 'proxyquire';;// now, you can mock files as you import them.const mocked =;// and, finnaly you can be sure, that you do something RIGHT.// next example will trigger errorconst mocked = proxyquire;
Your own setup
If you want to extend proxyquire, for example to
setup it as you want, and use it indirectly - you have to add some magic
// so you are using special version of proxyquire;
Where my-proxyquire.js is your file
;// this one creates `special` proxyquire for the file it useconst myProxyquire =moduleparent// now you can setup default behavior;// and this prevent caching. So in new place you will get new classdelete requirecacherequire;;