zl程序教程

您现在的位置是:首页 >  前端

当前栏目

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

AngularsetJSONJSON in by path Up
2023-09-14 08:59:18 时间

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'