diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3224d0e5e..4b4744cfa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2693,6 +2693,9 @@ importers: '@rspack/dev-server': specifier: 2.0.3 version: 2.0.3(@rspack/core@2.0.5) + cross-env: + specifier: 10.1.0 + version: 10.1.0 webpack-node-externals: specifier: 3.0.0 version: 3.0.0 @@ -21908,7 +21911,7 @@ snapshots: '@tailwindcss/node': 4.3.0 '@tailwindcss/oxide': 4.3.0 tailwindcss: 4.3.0 - webpack: 5.102.1(esbuild@0.28.0) + webpack: 5.102.1 '@tanstack/devtools-client@0.0.6': dependencies: @@ -30391,6 +30394,7 @@ snapshots: webpack: 5.102.1(esbuild@0.28.0) optionalDependencies: esbuild: 0.28.0 + optional: true terser-webpack-plugin@5.6.1(lightningcss@1.32.0)(webpack@5.102.1): dependencies: @@ -31349,6 +31353,7 @@ snapshots: - lightningcss - postcss - uglify-js + optional: true webpack@5.102.1(esbuild@0.28.0)(lightningcss@1.32.0): dependencies: diff --git a/rspack/nestjs/package.json b/rspack/nestjs/package.json index e70d7dd2d..0900951aa 100644 --- a/rspack/nestjs/package.json +++ b/rspack/nestjs/package.json @@ -5,7 +5,7 @@ "license": "MIT", "scripts": { "build": "rspack build", - "dev": "rspack dev", + "dev": "cross-env NODE_ENV=development rspack --watch --mode development", "start": "node dist/main.js" }, "dependencies": { @@ -20,6 +20,7 @@ "@rspack/cli": "2.0.5", "@rspack/core": "2.0.5", "@rspack/dev-server": "2.0.3", + "cross-env": "10.1.0", "webpack-node-externals": "3.0.0" } } diff --git a/rspack/nestjs/rspack.config.mjs b/rspack/nestjs/rspack.config.mjs index 9c437b372..5d5be3482 100644 --- a/rspack/nestjs/rspack.config.mjs +++ b/rspack/nestjs/rspack.config.mjs @@ -4,14 +4,13 @@ import { rspack } from '@rspack/core'; import { RunScriptWebpackPlugin } from 'run-script-webpack-plugin'; import nodeExternals from 'webpack-node-externals'; +const isDev = process.env.NODE_ENV !== 'production'; + export default defineConfig({ context: import.meta.dirname, target: 'node', entry: { - main: - process.env.NODE_ENV === 'production' - ? './src/main.ts' - : ['@rspack/core/hot/poll?100', './src/main.ts'], + main: isDev ? ['@rspack/core/hot/poll?100', './src/main.ts'] : './src/main.ts', }, output: { clean: true, @@ -61,18 +60,15 @@ export default defineConfig({ ], }, externalsType: 'commonjs', - plugins: [ - process.env.NODE_ENV !== 'production' && - new RunScriptWebpackPlugin({ - name: 'main.js', - autoRestart: false, - }), - ], - devServer: { - devMiddleware: { - writeToDisk: true, - }, - }, + plugins: isDev + ? [ + new RunScriptWebpackPlugin({ + name: 'main.js', + autoRestart: false, + }), + new rspack.HotModuleReplacementPlugin(), + ] + : [], externals: [ nodeExternals({ allowlist: [/@rspack\/core\/hot\/poll/], diff --git a/rspack/nestjs/src/main.ts b/rspack/nestjs/src/main.ts index 969a22d1f..7cbbb9521 100644 --- a/rspack/nestjs/src/main.ts +++ b/rspack/nestjs/src/main.ts @@ -1,14 +1,13 @@ -declare const module: any; - import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); await app.listen(3000); - if (module.hot) { - module.hot.accept(); - module.hot.dispose(() => app.close()); + + if (import.meta.webpackHot) { + import.meta.webpackHot.accept(); + import.meta.webpackHot.dispose(() => app.close()); } } bootstrap(); diff --git a/rspack/nestjs/tsconfig.build.json b/rspack/nestjs/tsconfig.build.json new file mode 100644 index 000000000..2fe1df273 --- /dev/null +++ b/rspack/nestjs/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/rspack/nestjs/tsconfig.json b/rspack/nestjs/tsconfig.json new file mode 100644 index 000000000..cb364cc58 --- /dev/null +++ b/rspack/nestjs/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "types": ["@rspack/core/module"], + "module": "ESNext", + "moduleResolution": "bundler", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2021", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true + }, + "include": ["src/**/*"] +}