Skip to content

baron-code-factory/typescript-references

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

これは?

ほかの プロジェクトを参照する際の注意点など...

全体像

➜ lsd --tree --depth 2
  .
├──   a.json
├──   client
│  ├──   node_modules
│  ├──   package.json
│  ├──   src
│  ├──   tsconfig.json
│  └──   yarn.lock
├──   README.md
└──   shared
   ├──   node_modules
   ├──   package.json
   ├──   src
   ├──   tsconfig.json
   ├──   x.ts
   └──   yarn.lock

背景 や 前提条件

client/ から shared/ 参照したい

yarn workspace無し

この際の設定や注意点

client/tsconfig.json

"compilerOptions": {
    // distだけだと バッティングが怖い
    "outDir": "../dist/client"

    // ここより上は参照不可能
    // 思わぬファイル出力される場合あるしつけとけよ
    "rootDir": "src" 

    // import の時のパス
    // こんなのができる
    // import {some} from "src/foo/some"
    // tsc した際の解決はないので それは 別途考慮が必要
    // "." 以外はやめといたほうがいい !!!!!!!!!!!!!!
    "baseUrl": "."

    // tsc した際の解決はないので それは 別途考慮が必要
    "paths": {
        // これらを使いたいならば バベルをいれとけ !!!!!!!!!!!!!!
        // 開発中は OK tsc 後は動かない
        "~@shared/*": [
        "../dist/shared/*",
        "../shared/*",
        ],
        "shared/*": [
        "../dist/shared/*",
        "../shared/*"
        ]
    },   
}
"references": [
    // shared import する時に必要
    { "path": "../shared" }
],

shared/tsconfig.json

"compilerOptions": {
    // 参照される場合必要
    "composite": true,
}

tsconfig.some.json

exteds して使う

あまり使わないほうがいい

つかうなら baseUrl"." にする
こうすると tsconfig.some.json がある
所基準になり、 outDir なども ひっぱられる

つかうなら strict を厳しくぐらいの継承が良いか

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published