![](/img/trans.png)
[英]Correct way of using typescript files from modules in typescript node+express project? currently throwing Error: Cannot find module
[英]Is there a way to abstract the import from a node module using typescript config files in the same style as the 'paths' property?
我正在創建私有節點模塊,目前這些模塊的結構可能會發生很大變化,這可能意味着將現有代碼拆分為多個包。
如果我有 100 個文件從不再包含導入的 package 導入,我可以進行查找和替換,但是從 package 導入類時會變得更加困難......
所以像:
import { thing1, thing2} from 'my-package';
未來可能需要:
import { thing1} from 'my-package';
import { thing2} from 'my-package2';
您可以像這樣使用 tsconfig 抽象導入:
"paths": {
"@shared/*": ["app/shared/*"]
}
但是我想不出一種方法來對節點模塊做同樣的事情,所以如果有更大的變化,我只需要改變 1 行。 這可能嗎?
檢查https://github.com/nrwl/nx他們可以幫助您使用 monorepo 方法。 您可以將系統拆分為應用程序和庫。
創建 index.ts 文件,導入和導出您的模塊:
import { assign, assignWith } from 'lodash';
import { addDays } from 'date-fns';
export { assign, assignWith, addDays };
並從該索引導入模塊:
import { assign, addDays } from './index';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.