Appearance
NestJs
命令行安装
bash
pnpm i -g @nestjs/cli
bash
yarn global add @nestjs/cli
bash
npm i -g @nestjs/cli
创建新项目
bash
nest new project-name
常用命令
可以使用 nest -h
来查看
name | alias | description |
---|---|---|
application | application | Generate a new application workspace |
class | cl | Generate a new class |
configuration | config | Generate a CLI configuration file |
controller | co | Generate a controller declaration |
decorator | d | Generate a custom decorator |
filter | f | Generate a filter declaration |
gateway | ga | Generate a gateway declaration |
guard | gu | Generate a guard declaration |
interceptor | itc | Generate an interceptor declaration |
interface | itf | Generate an interface |
middleware | mi | Generate a middleware declaration |
module | mo | Generate a module declaration |
pipe | pi | Generate a pipe declaration |
provider | pr | Generate a provider declaration |
resolver | r | Generate a GraphQL resolver declaration |
service | s | Generate a service declaration |
library | lib | Generate a new library within a monorepo |
sub-app | app | Generate a new application within a monorepo |
resource | res | Generate a new CRUD resource |
升级到 10.x 后改动
升级到 10.x 后我们可以使用 swc 启动项目,swc 会使项目启动速度有很大提升。使用 swc 后我们需要做一些改动。
安装 SWC
bash
pnpm i -D @swc/cli @swc/core
项目改动
json
"scripts": {
"build": "nest build -b swc --type-check",
"build": "nest build",
"start:dev": "nest start -b swc --type-check --watch",
"start:dev": "nest start --watch"
}
nest-cli.json 中添加
json
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"builder": "swc",
"typeCheck": true
}
}