[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'

 

posted @ 2017-07-28 02:30  Zhentiw  阅读(219)  评论(0编辑  收藏  举报