Skip to content

Commit

Permalink
Hot module reload (doesn't work due to webpack issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasofizada committed Feb 10, 2021
1 parent 5fd8d4c commit fda65ed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './AppModule';

// TODO(GLOBAL): https://github.com/microsoft/TypeScript/issues/2845

declare const module: any;

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);

if (module.hot) {
module.hot.accept();
module.hot.dispose(() => app.close());
}
}
bootstrap();
22 changes: 22 additions & 0 deletions webpack-hmr.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');

module.exports = function(options) {
return {
...options,
entry: ['webpack/hot/poll?100', options.entry],
watch: true,
externals: [
nodeExternals({
allowlist: ['webpack/hot/poll?100'],
}),
],
plugins: [
...options.plugins,
new webpack.HotModuleReplacementPlugin(),
new webpack.WatchIgnorePlugin([/\.js$/, /\.d\.ts$/]),
new StartServerPlugin({ name: options.output.filename }),
],
};
};

0 comments on commit fda65ed

Please sign in to comment.