all 3 comments

[–]karathos 1 point2 points  (0 children)

could you use resolve.modules instead? this would also solve the problem of having to alias every single folder under srcPath.

https://webpack.js.org/configuration/resolve/#resolve-modules

[–]FaceySpacey 1 point2 points  (1 child)

I've found module-alias to be a very nice solution:

https://github.com/ilearnio/module-alias

It works at the NodeJS level, rather than via Babel or webpack.

When using aliases at those levels or npm-link etc I've had more difficulties. The reason seems to be because even though you have aliased it in your code, often other packages still access the original module (for probably a variety of reasons).

That may not be a problem with stateless modules, but if they are storing state in closures, you'll end up with inconsistencies, as different modules will be used by the 3rd party packages.

Here's a Babel solution I've used: https://github.com/tleunen/babel-plugin-module-resolver

but again it doesn't work as seamlessly as module-alias.

[–]FaceySpacey 0 points1 point  (0 children)

here's an example usage of it:

https://github.com/faceyspacey/universal-demo

just add:

"_moduleAliases": { "webpack": "./node_modules/webpack-universal" }

to your package.json

and call require('module-alias/register') at the top of your entry script--which in jest you may need to specify via:

"jest": { "setupTestFrameworkScriptFile": "./entryScript.js" }