Angular10 中配置@路径别名

2022-08-01,,,

Angular10配置@路径别名

Angular10中的项目文件结构 中文网站

Angular10中的tsconfig配置被分成了四个文件

  1. tsconfig.json工作空间中各项目的默认TSP配置
  2. tsconfig.base.json工作空间的所有项目使用的基础TS配置,所有其它的配置文件都是继承自这个基础文件
  3. tsconfig.app.json应用专属的TS配置包括TSAngular模板编译器的选项
  4. tsconfig.spec.json应用测试的TS配置
主要配置是在tsconfig.base.json
  1. 因为在TS的配置中有介绍,在compilerOptions中添加字段paths来进行声明映射

    {
        "compileOnSave": false,
        "compilerOptions": {
            "baseUrl": "./",
            "outDir": "./dist/out-tsc",
            "sourceMap": true,
            "declaration": false,
            "downlevelIteration": true,
            "experimentalDecorators": true,
            "moduleResolution": "node",
            "importHelpers": true,
            "target": "es2015",
            "module": "es2020",
            "lib": ["es2018", "dom"],
            "paths": {
                "@/*": ["src/*"]
            }
        }
    }
    
  2. 之后使用@/就相当于使用src/

  3. 使用了@/

  4. 没有使用@/

本文地址:https://blog.csdn.net/weixin_43972992/article/details/107410198

《Angular10 中配置@路径别名.doc》

下载本文的Word格式文档,以方便收藏与打印。