-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9cddf1
commit bc9913f
Showing
6 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# root3 | ||
|
||
This is a simple example for typescript monorepo, using [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { doubleNumbers } from "@monorepo/foo"; | ||
|
||
export const run = () => { | ||
const value = doubleNumbers([1, 2, 3]); | ||
return value; | ||
}; | ||
|
||
console.log(run()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const hello = (to: string) => { | ||
console.log(`hello ${to}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* The module name can be just './hello'. | ||
But '#foo/hello' is demonstration of "Path Mapping" of `tsconfig` | ||
and "Subpath imports"(defined in package.json's `imports` field) of node.js */ | ||
import { hello } from "#foo/hello"; | ||
// import { hello } from './hello' => this will work, too | ||
// import { hello } from '@monorepo/foo/hello' // => this will not work for tsc, without additional configuration on tsconfig.json | ||
|
||
hello("world"); | ||
|
||
export const doubleNumbers = (data: number[]) => data.map((i) => i * 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "CommonJS", | ||
"rootDir": ".", | ||
"baseUrl": "packages", | ||
"paths": { | ||
"@monorepo/*": ["*"], | ||
"#foo/*": ["foo/*"], | ||
"#bar/*": ["bar/*"], | ||
"#*": ["*"] | ||
}, | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"removeComments": true, | ||
"composite": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"sourceMap": true, | ||
"esModuleInterop": true, | ||
"incremental": true, | ||
"resolveJsonModule": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters