-
Notifications
You must be signed in to change notification settings - Fork 7k
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
6688a6b
commit bfd9cbb
Showing
26 changed files
with
1,770 additions
and
125 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,15 @@ | ||
# 适配器 | ||
VITE_ADAPTER=nest | ||
|
||
# 应用名称 | ||
VITE_APP_NAME=Vben Server | ||
|
||
# 应用入口 | ||
VITE_APP_PATH=src | ||
|
||
# 应用入口的导出变量 | ||
VITE_EXPORT_NAME=default | ||
|
||
# 立即启动 | ||
VITE_IMMEDIATE=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_VISUALIZER=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 端口号 | ||
VITE_PORT=5777 |
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,2 @@ | ||
# 端口号 | ||
VITE_PORT=3000 |
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,7 @@ | ||
{ | ||
"explorer.fileNesting.patterns": { | ||
"*.ts": "${capture}.module.ts,${capture}.service.ts,${capture}.dto.ts,${capture}.controller.ts", | ||
"*.module.ts": "${capture}.module.ts,${capture}.service.ts,${capture}.dto.ts", | ||
"*.service.ts": "${capture}.dto.ts" | ||
} | ||
} |
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 @@ | ||
{ | ||
"name": "@vben/backend-nest", | ||
"version": "0.0.1", | ||
"description": "", | ||
"private": true, | ||
"license": "MIT", | ||
"author": "", | ||
"scripts": { | ||
"build": "pnpm vite build --mode production", | ||
"build:analyze": "pnpm vite build --mode analyze", | ||
"dev": "pnpm vite --mode development", | ||
"preview": "vite preview", | ||
"typecheck": "vue-tsc --noEmit --skipLibCheck" | ||
}, | ||
"dependencies": { | ||
"@nestjs/common": "^10.0.0", | ||
"@nestjs/core": "^10.0.0", | ||
"@nestjs/platform-express": "^10.0.0", | ||
"reflect-metadata": "^0.2.0", | ||
"rxjs": "^7.8.1" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^10.0.0", | ||
"@types/express": "^4.17.17", | ||
"@types/node": "catalog:" | ||
} | ||
} |
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,5 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
@Module({}) | ||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class | ||
export class AppModule {} |
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,29 @@ | ||
import type { INestApplication } from '@nestjs/common'; | ||
|
||
import { NestFactory } from '@nestjs/core'; | ||
|
||
import { AppModule } from './index.module'; | ||
|
||
let app: INestApplication; | ||
|
||
async function createApp() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
app.enableCors(); | ||
|
||
return app; | ||
} | ||
|
||
export async function useApp() { | ||
if (!app) { | ||
app = await createApp(); | ||
} | ||
|
||
return app; | ||
} | ||
|
||
export async function bootstrap() { | ||
const app = await useApp(); | ||
|
||
await app.listen(import.meta.env.VITE_PORT); | ||
} |
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,5 @@ | ||
import { bootstrap, useApp } from './app'; | ||
|
||
if (import.meta.env.PROD) bootstrap(); | ||
|
||
export default useApp(); |
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,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] | ||
} |
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,12 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "@vben/tsconfig/node.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"#/*": ["./src/*"] | ||
}, | ||
"types": ["vite/client"] | ||
}, | ||
"include": ["src/**/*.ts"] | ||
} |
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 { defineConfig } from '@vben/vite-config'; | ||
|
||
export default defineConfig(async () => { | ||
return { | ||
server: {}, | ||
vite: {}, | ||
}; | ||
}, 'server'); |
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
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
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
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
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,63 @@ | ||
import type { UserConfig } from 'vite'; | ||
|
||
import type { DefineServerOptions } from '../typing'; | ||
|
||
import { defineConfig, loadEnv, mergeConfig } from 'vite'; | ||
|
||
import { loadServerPlugins } from '../plugins'; | ||
import { loadServerEnv } from '../utils/env'; | ||
import { getCommonConfig } from './common'; | ||
|
||
function defineServerConfig(userConfigPromise?: DefineServerOptions) { | ||
return defineConfig(async (config) => { | ||
const options = await userConfigPromise?.(config); | ||
const { port, ...envConfig } = await loadServerEnv(); | ||
const { command, mode } = config; | ||
const { server = {}, vite = {} } = options || {}; | ||
const root = process.cwd(); | ||
const isBuild = command === 'build'; | ||
const env = loadEnv(mode, root); | ||
|
||
const plugins = await loadServerPlugins({ | ||
env, | ||
injectMetadata: true, | ||
isBuild, | ||
mode, | ||
noElement: true, | ||
...envConfig, | ||
...server, | ||
}); | ||
|
||
const serverConfig: UserConfig = { | ||
esbuild: { | ||
drop: isBuild | ||
? [ | ||
// 'console', | ||
'debugger', | ||
] | ||
: [], | ||
legalComments: 'none', | ||
}, | ||
optimizeDeps: { | ||
exclude: [ | ||
'@nestjs/microservices', | ||
'@nestjs/websockets', | ||
'cache-manager', | ||
'class-transformer', | ||
'class-validator', | ||
'fastify-swagger', | ||
], | ||
}, | ||
plugins, | ||
server: { host: true, port }, | ||
}; | ||
|
||
const mergedCommonConfig = mergeConfig( | ||
await getCommonConfig(), | ||
serverConfig, | ||
); | ||
return mergeConfig(mergedCommonConfig, vite); | ||
}); | ||
} | ||
|
||
export { defineServerConfig }; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './config'; | ||
export * from './options'; | ||
export * from './plugins'; | ||
export { loadAndConvertEnv } from './utils/env'; | ||
export { loadApplicationEnv as loadAndConvertEnv } from './utils/env'; |
Oops, something went wrong.