JavaScript

Webpack: New Resolve Root Path

- src
 |- components
 ||- CatComponent.js
 ||- DogComponent.js
- node_modules

/* src/components/DogComponent.js */
import CatComponent from 'components';

For importing from another directive to work like imports from node_modules like above, configure webpack.

Add whichever directory in the resolve part of the config:

resolve: {
  modulesDirectories: ['src', 'node_modules']
}

And for VSCode to recognize the path, provide definition and autocomplete on click, add this to your jsconfig.js or tsconfig.js file:

{
  "compilerOptions": {
    "baseUrl": "src"
  }
}
Standard

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.