You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this scenario, Button is the module you would want to use most of the time. Caption and Icon are only being used inside of the scope of the Button file.
Whenever you want to require a module from a file in a directory you will have two choices to import these files:
Import the files directly like this import Button from './Button/Button'. Since it this case Caption and Icon should only be used for the scope for Button. We could strive for shorter import statement that would create the illusion of stronger coupling.
Create an index.js file for each directory and mimic Node.js resolution behavior. While this shortens the import statement to import Button from './Button' increasing the coupling and decreasing moving parts, it creates additional files to maintain.
Ideally, we would want short import statements without the need to create additional files that link to the file in question. And this is where rollup-plugin-named-directory comes in.
Whenever Rollup encounters <dir>, it will now look for <dir>/<dir>.js first. (Example: If the directory is Button, it will now look for Button/Button.js first)
If the plugin isn't able to find the file in question, it will continue with the typical resolution behavior as dictated by Rollup and other plugins.
Make sure to provide the file extensions in.
It's possible to provide multiple strings which will be resolved in the order they have been defined.