首页 > 其他 > 详细

TypeScript--路径映射

时间:2021-04-23 10:48:59      阅读:19      评论:0      收藏:0      [点我收藏+]

Configure the path mapping(路径映射) in jsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
      "t/*": ["./test/*"]
     }
  }
}

文件结构

- src
	- pages
		- home
			- home.ts
			- detail.ts
		- mine
			- mine.ts
			- setting.ts
		- login
			- login.ts
			- register.ts
	- components
		- label
			- index.ts
		- button
			- index.ts
	- app.ts

- test
	- module
		- a.ts
	- test.ts

test.ts

<!-- 非 path mapping -->
import {a} from "./module/a";
import {app} from "../src/app";
import {home} from "../src/pages/home/home";
import {button} from "../src/components/button";


<!-- path mapping -->
import {a} from "t/module/a";
import {app} from "@/app";
import {home} from "@/pages/home/home";
import {button} from "@/components/button";

app.ts

<!-- 非 path mapping -->
import {a} from "../test/module/a";
import {test} from "../test/test";
import {home} from "./pages/home/home";
import {button} from "./components/button";

<!-- path mapping -->
import {a} from "t/module/a";
import {test} from "t/test";
import {home} from "@/pages/home/home";
import {button} from "@/components/button";

login.ts

<!-- 非 path mapping -->
import {a} from "../../../test/module/a";
import {test} from "../../../test/test";
import {app} from "../../app";
import {home} from "../home/home";
import {button} from "../../components/button";


<!-- path mapping -->
import {a} from "t/module/a";
import {test} from "t/test";
import {app} from "@/app";
import {home} from "@/pages/home/home";
import {button} from "@/components/button";

TypeScript--路径映射

原文:https://www.cnblogs.com/nipeiqing/p/14692463.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!