nest에서 nodemon 실행시 렉걸리고 작동이 안 됨.
대신 webpack-node-externals
설치 후 진행 가능함.
npm i --save-dev webpack-node-externals run-script-webpack-plugin webpack
최상위루트에 webpack-hmr.config.js
파일 생성
const nodeExternals = require('webpack-node-externals');
const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin');
module.exports = function (options, webpack) {
return {
...options,
entry: ['webpack/hot/poll?100', options.entry],
externals: [
nodeExternals({
allowlist: ['webpack/hot/poll?100'],
}),
],
plugins: [
...options.plugins,
new webpack.HotModuleReplacementPlugin(),
new webpack.WatchIgnorePlugin({
paths: [/\\.js$/, /\\.d\\.ts$/],
}),
new RunScriptWebpackPlugin({ name: options.output.filename, autoRestart: false }),
],
};
};
main.ts 파일에 아래 내용 추가
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();
package.json에 스크립트 추가
"start:dev": "nest build --webpack --webpackPath webpack-hmr.config.js --watch"npm
단축 명령어 등록해두고 본인이 지정한 명령어 실행
npm run s
잘 실행되는 거 확인 가능함