Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rspack/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
28 changes: 12 additions & 16 deletions rspack/nestjs/rspack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/],
Expand Down
9 changes: 4 additions & 5 deletions rspack/nestjs/src/main.ts
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 4 additions & 0 deletions rspack/nestjs/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
19 changes: 19 additions & 0 deletions rspack/nestjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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/**/*"]
}
Loading