Skip to content

Commit d34bd08

Browse files
author
manuschillerdev
committed
🦀 - initial commit
0 parents  commit d34bd08

21 files changed

+17992
-0
lines changed

.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
pnpm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
14+
# OS
15+
.DS_Store
16+
17+
# Tests
18+
/coverage
19+
/.nyc_output
20+
21+
# IDEs and editors
22+
/.idea
23+
.project
24+
.classpath
25+
.c9/
26+
*.launch
27+
.settings/
28+
*.sublime-workspace
29+
30+
# IDE - VSCode
31+
.vscode/*
32+
!.vscode/settings.json
33+
!.vscode/tasks.json
34+
!.vscode/launch.json
35+
!.vscode/extensions.json

.swcrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"sourceMaps": true,
3+
"module": {
4+
"type": "commonjs",
5+
"strict": true
6+
},
7+
"jsc": {
8+
"target": "es2020",
9+
"parser": {
10+
"syntax": "typescript",
11+
"decorators": true
12+
},
13+
"transform": {
14+
"legacyDecorator": true,
15+
"decoratorMetadata": true
16+
},
17+
"keepClassNames": true
18+
}
19+
}

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Using NestJS with SWC
2+
3+
This experimental project aims to explore the possibilities of using `swc` with `NestJS`.
4+
Tries to mimic a non-trivial project with `TypeORM`, `nestjsx/crud`, and dynamically loaded entities.
5+
6+
foo
7+
8+
## Features
9+
10+
- dev-server with
11+
- experimental "hot-reloading"
12+
- transpiled by `swc` instead of `ts-loader`
13+
- does not write transpiled files to disk (no `dist` folder in dev)
14+
- supports source-maps (correct mappings of line numbers in errors to Typescript source files)
15+
- alternative webpack setup (disclaimer: totally not happy with this)
16+
- uses `swc-loader` instead of `ts-loader`
17+
- removes `ForkTsCheckerWebpackPlugin`
18+
- uses a HMR config based on the docs
19+
- ⚠️ does not seem reliable (code changes are sometimes not reflected in responses). Unclear if `swc-loader` might cause or if the setup is wrong.
20+
- ⚠️ does not have proper source-map support
21+
- ⚠️ does not support generic glob references to entities
22+
- testing (`jest`)
23+
- uses `@swc/jest` for transforms
24+
- supports coverage reports
25+
- supports watch mode
26+
- supports e2e-test. ⚠️ needed to change `import * as request from "supertest";` to `import request from "supertest";` to make it work
27+
28+
## Benchmarks
29+
30+
### jest
31+
32+
```bash
33+
❯ hyperfine "npm run test" # with ts-jest
34+
Benchmark #1: npm run test
35+
Time (mean ± σ): 3.436 s ± 0.349 s [User: 4.680 s, System: 0.543 s]
36+
Range (min … max): 3.156 s … 4.211 s 10 runs
37+
38+
❯ hyperfine "npm run test" # with @swc/jest
39+
Benchmark #1: npm run test
40+
Time (mean ± σ): 1.447 s ± 0.020 s [User: 1.268 s, System: 0.323 s]
41+
Range (min … max): 1.428 s … 1.500 s
42+
```
43+
44+
## Caveats
45+
46+
- Sometimes, TypeORM does not close the connection properly. In this case, the server needs to be restarted manually
47+
- HMR is 100% experimental. Open to any ideas on how this could be implemented better.

nest-cli.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"collection": "@nestjs/schematics",
3+
"sourceRoot": "src"
4+
}

0 commit comments

Comments
 (0)