Angular cli 项目中的绝对路径 [英] Absolute path in Angular cli project
问题描述
如何在 angular cli 生成的项目中使用绝对路径?
所以我有这个路径:src ->应用程序->分享
我想写 import {} from 'shared/ffdsdf/my.module.ts'
而不是 '../shared/ffdsdf/my.module.ts'
TypeScript 功能允许这样做.
您可以修改您的 src/tsconfig.json
文件以启用此功能,在 compilerOptions
下,添加以下内容:
您显然可以根据需要更改模式键和值.您添加或删除文件夹,您可以更改顺序等.
你也可以选择一个前缀而不是 *
(特别是如果它出现问题),你可以使用类似 ~/*
的东西,然后你的导入将是所有来自'~/shared/sample'
等
How can I use absolute path in an angular cli generated project?
So I have this path : src -> app -> shared
and I would like to write import {} from 'shared/ffdsdf/my.module.ts'
instead of '../shared/ffdsdf/my.module.ts'
There is a TypeScript feature that allows this.
You can modify your src/tsconfig.json
file to enable this, under compilerOptions
, add the following:
{ "compilerOptions": { // ... "paths": { "*": [ "./*", "app/*", "../node_modules/*" ] } }
You can obviously change the pattern key and values as needed. You add or remove folders, you can change the order, etc.
You can also choose a prefix instead of just *
(especially if it cases problems), you can use something like ~/*
, and your imports will then be all from '~/shared/sample'
etc.
这篇关于Angular cli 项目中的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!