ng7 设置文件路径别名

时间:2023-03-09 09:11:49
ng7 设置文件路径别名

/tsconfig.json

配置后重启服务

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es5",
    "typeRoots": ["node_modules/@types"],
    "lib": ["es2018", "dom"],

    "paths": {
      "~app/*": ["src/app/*"],
      "~shared/*": ["src/app/shared/*"]
    }

  }
}

使用

// import { MSG } from "../../hello";
import { MSG } from "~app/hello";
import { name } from "~shared/shared";