Skip to content

Commit f8eba53

Browse files
authored
Add documentation and example code for projectReferences (#1184)
* Added Project References documentation and example * Fix links & Typos * Clarify relationship between ts-laoder and tsc
1 parent 46d9761 commit f8eba53

21 files changed

+5139
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ This flag enables caching for some FS-functions like `fileExists`, `realpath` an
713713

714714
ts-loader has opt-in support for [project references](https://www.typescriptlang.org/docs/handbook/project-references.html). With this configuration option enabled, `ts-loader` will incrementally rebuild upstream projects the same way `tsc --build` does. Otherwise, source files in referenced projects will be treated as if they’re part of the root project.
715715

716+
In order to make use of this option your project needs to be correctly configured to build the project references and then to use them as part of the build. See the [Project References Guide](REFERENCES.md) and the example code in the examples which can be found [here](examples/project-references-example/).
717+
716718
### Usage with webpack watch
717719

718720
Because TS will generate .js and .d.ts files, you should ignore these files, otherwise watchers may go into an infinite watch loop. For example, when using webpack, you may wish to add this to your webpack.conf.js file:

REFERENCES.md

Lines changed: 331 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib/
2+
node_modules/
3+
dist/
4+
tsconfig.tsbuildinfo
5+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# TypeScript Project References Demo
2+
3+
This repo is forked from https://github.com/RyanCavanaugh/project-references-demo, which is a repo to demonstrate the use of project references in TypeScript. It has been extended to show how project references can be used in a project using the following:
4+
5+
* TypeScript
6+
* Webpack
7+
* ts-loader
8+
* yarn workspaces
9+
10+
This repo is described in the article [here](/REFERENCES.md).
11+
12+
## Installation
13+
```
14+
yarn install
15+
```
16+
17+
## Running
18+
```
19+
yarn start
20+
```
21+
Go to localhost:8080 in your browser to view the output. Edit files in the <code>packages</code> to see the changes in the browser.
22+
23+
24+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "project-references-demo",
3+
"version": "1.0.0",
4+
"description": "To compare the performance of project references with webpack & ts-loader vs webpack and tsc run in a separate process.",
5+
"main": "index.js",
6+
"private": true,
7+
"workspaces": ["packages/*"],
8+
"scripts": {
9+
"start": "webpack-dev-server",
10+
"build": "webpack"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/appzuka/project-references-demo.git"
15+
},
16+
"author": "",
17+
"license": "ISC",
18+
"bugs": {
19+
"url": "https://github.com/appzuka/project-references-demo.git/issues"
20+
},
21+
"homepage": "https://github.com/appzuka/project-references-demo.git",
22+
"dependencies": {
23+
"@types/node": "^14.6.1",
24+
"@types/react": "^16.9.48",
25+
"fork-ts-checker-webpack-plugin": "^5.1.0",
26+
"html-webpack-plugin": "^4.4.1",
27+
"react": "^16.13.1",
28+
"react-dom": "^16.13.1",
29+
"ts-loader": "^8.0.3",
30+
"tsconfig-paths-webpack-plugin": "^3.3.0",
31+
"typescript": "^3.9.7",
32+
"webpack": "^4.44.1",
33+
"webpack-cli": "^3.3.12",
34+
"webpack-dev-server": "^3.11.0"
35+
}
36+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type Size = "small" | "medium" | "large";
2+
3+
interface Animal {
4+
size: Size;
5+
}
6+
7+
export {
8+
Animal,
9+
Size
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Animal, Size } from './animal';
2+
import { makeRandomName } from '@myscope/core';
3+
4+
interface Dog extends Animal {
5+
woof(): void;
6+
name: string;
7+
}
8+
9+
const sizes = "small medium large".split(' ');
10+
const barks = "Woof Yap Growl".split(' ');
11+
12+
function createDog(): Dog {
13+
return ({
14+
size: sizes[Math.floor(Math.random() * sizes.length)] as Size,
15+
woof: function(this: Dog) {
16+
return(`${this.name} says ${barks[Math.floor(Math.random() * barks.length)]}!`);
17+
},
18+
name: makeRandomName(),
19+
// deliberateError: 42
20+
});
21+
}
22+
23+
export {
24+
Dog,
25+
createDog
26+
}
27+
28+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Animal } from './animal';
2+
3+
import { createDog, Dog } from './dog';
4+
export { Animal, createDog, Dog };
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@myscope/animals",
3+
"version": "1.0.0",
4+
"description": "Animals package",
5+
"main": "lib/index.js",
6+
"directories": {
7+
"lib": "lib"
8+
},
9+
"license": "ISC"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../tsconfig-base.json",
3+
"compilerOptions": {
4+
"outDir": "lib",
5+
"rootDir": ".",
6+
},
7+
"references": [
8+
{ "path": "../core" }
9+
]
10+
}

0 commit comments

Comments
 (0)