[Angular] Omit relative path by set up in tsconfig.json

For example, inside you component you want to import a file from two up directory:

import store from '../../store'

This becomes a little bit problematic because the component can be really nested.

To solve this problem, we can define "paths" in tsconfig.json:

{
  ...
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "store": ["src/store.ts"]
    },
    ...
    "target": "es5"
  }
}

Now for each component, we can just use:

import store from 'store'
原文地址:https://www.cnblogs.com/Answer1215/p/7248164.html