
- Resolve aliases jest test webpack update#
- Resolve aliases jest test webpack manual#
- Resolve aliases jest test webpack full#
The Webpack config to use when compiling your react app for development or production. I tried to tap into webpack and jest configs with react-app-rewired, and this is my config to allow overrides and inject aliases: // config-overrides.js
Resolve aliases jest test webpack full#
Resolve aliases jest test webpack manual#
These many configurations are Manual Knowledge because Onboarding ExperienceĪlso for new joiners of Team, its hard to wrap the head around aliases once you are using them everywhere. Source of TruthĪnother trouble is to maintain a single source of truth for the Aliases, as this configuration is everywhere, who gets to become the source of truth. In different tools, there is a different way to define aliases and this makes tricky to define and maintain the aliases. In previous post, we had seen the benefits of Aliases in Webpackīut what about other bundlers like Rollup? Or Test environment like Jest?
Resolve aliases jest test webpack update#
Will update this post if I find a good solution to reduce duplication / files that need to be touched when updating an aliased path.Aliases are very handy be it in CLI or in FrontEnd development.

The tricky part is how some of them are formatted a bit different from each other, like jest requiring regex paths. I’ll probably reconsider this a bit and see if I can make some of these paths / names constants in some location in the app and use them in the needed configs. I don’t like how many duplicated paths are present here. Now check this all worked by hovering over the Checkbox (or whatever your module is you’re working with) in the import import Checkbox from 'CoreComponents/Checkbox', and you should now see the information about that module populate as before. Obviously modify the static/dist option to be wherever webpack is building your static files out to. Makes sure to put in those exclude options to avoid slowing the application down traversing files it doesn’t need to.

You’ll probably hit an error like this when you try to run them after updating your imports. Next on our list is to get our tests passing again. I’m going to just use CoreComponents for this example but you can follow whatever convention you think is most clear. It will also help you in 3 weeks when you have forgotten about the magic you’ve forged here. This will help other developers who don’t know about the under the hood aliases to realize that your aliased directory name isn’t an actual directory on the file system. One thing worth considering here is making the alias name CoreComponents something more obviously different than your usual directories, for example or some other non directory name symbol. Run a Webpack build to confirm, though if you’re using Eslint it may be yelling at you along with VScode, and your Jests tests will have import errors. Import Checkbox from ' CoreComponents/Checkbox ' Īnd your application should build.
