Skip to content

Commit 2a57932

Browse files
authored
fix: refine nestjs example (#473)
1 parent 6726ced commit 2a57932

6 files changed

Lines changed: 47 additions & 23 deletions

File tree

pnpm-lock.yaml

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rspack/nestjs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"scripts": {
77
"build": "rspack build",
8-
"dev": "rspack dev",
8+
"dev": "cross-env NODE_ENV=development rspack --watch --mode development",
99
"start": "node dist/main.js"
1010
},
1111
"dependencies": {
@@ -20,6 +20,7 @@
2020
"@rspack/cli": "2.0.5",
2121
"@rspack/core": "2.0.5",
2222
"@rspack/dev-server": "2.0.3",
23+
"cross-env": "10.1.0",
2324
"webpack-node-externals": "3.0.0"
2425
}
2526
}

rspack/nestjs/rspack.config.mjs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import { rspack } from '@rspack/core';
44
import { RunScriptWebpackPlugin } from 'run-script-webpack-plugin';
55
import nodeExternals from 'webpack-node-externals';
66

7+
const isDev = process.env.NODE_ENV !== 'production';
8+
79
export default defineConfig({
810
context: import.meta.dirname,
911
target: 'node',
1012
entry: {
11-
main:
12-
process.env.NODE_ENV === 'production'
13-
? './src/main.ts'
14-
: ['@rspack/core/hot/poll?100', './src/main.ts'],
13+
main: isDev ? ['@rspack/core/hot/poll?100', './src/main.ts'] : './src/main.ts',
1514
},
1615
output: {
1716
clean: true,
@@ -61,18 +60,15 @@ export default defineConfig({
6160
],
6261
},
6362
externalsType: 'commonjs',
64-
plugins: [
65-
process.env.NODE_ENV !== 'production' &&
66-
new RunScriptWebpackPlugin({
67-
name: 'main.js',
68-
autoRestart: false,
69-
}),
70-
],
71-
devServer: {
72-
devMiddleware: {
73-
writeToDisk: true,
74-
},
75-
},
63+
plugins: isDev
64+
? [
65+
new RunScriptWebpackPlugin({
66+
name: 'main.js',
67+
autoRestart: false,
68+
}),
69+
new rspack.HotModuleReplacementPlugin(),
70+
]
71+
: [],
7672
externals: [
7773
nodeExternals({
7874
allowlist: [/@rspack\/core\/hot\/poll/],

rspack/nestjs/src/main.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
declare const module: any;
2-
31
import { NestFactory } from '@nestjs/core';
42
import { AppModule } from './app.module';
53

64
async function bootstrap() {
75
const app = await NestFactory.create(AppModule);
86
await app.listen(3000);
9-
if (module.hot) {
10-
module.hot.accept();
11-
module.hot.dispose(() => app.close());
7+
8+
if (import.meta.webpackHot) {
9+
import.meta.webpackHot.accept();
10+
import.meta.webpackHot.dispose(() => app.close());
1211
}
1312
}
1413
bootstrap();

rspack/nestjs/tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
4+
}

rspack/nestjs/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"types": ["@rspack/core/module"],
4+
"module": "ESNext",
5+
"moduleResolution": "bundler",
6+
"declaration": true,
7+
"removeComments": true,
8+
"emitDecoratorMetadata": true,
9+
"experimentalDecorators": true,
10+
"allowSyntheticDefaultImports": true,
11+
"target": "ES2021",
12+
"sourceMap": true,
13+
"outDir": "./dist",
14+
"baseUrl": "./",
15+
"incremental": true,
16+
"skipLibCheck": true
17+
},
18+
"include": ["src/**/*"]
19+
}

0 commit comments

Comments
 (0)