H.org
  • Questions

Adding Support For Absolute Imports

  1. javascript
  2. react

When working on large projects, you may start to break your components directory down into several domains or categories. This starts to become cumbersome as your directories grow:

import Component from "../../../../component/component";

Add the following to your jsconfig.json or tsconfig.json at the root of the project in order to enable absolute imports:

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  ...
}

This will then allow you to import from the base directory defined in the compilerOptions above:

import Component from "component/component";
Ko-Fi button Support Me on Ko-fi

Created with lots of green tea and 11ty

Opinions are solely my own and not those of my employer.

Privacy Policy - Licenses