Jos*_*lez 5 node.js webpack-dev-server nestjs
我已按照文档中的步骤操作:
\n\nhttps://docs.nestjs.com/techniques/hot-reload
\n\n我正在运行此命令:npm run webpack但它关闭了,它返回了提示,并且不会继续监视文件:
gabriel@roraima-tv:/var/www/studying/tera-ping-pong$ npm run webpack\n\n > tera-ping-pong@0.0.0 webpack /var/www/studying/tera-ping-pong\n > webpack --config webpack.config.js\n\n\n webpack is watching the files\xe2\x80\xa6\n\n Hash: 6e13d56ba7d77331e5c2\n Version: webpack 4.23.1\n Time: 3014ms\n Built at: 11/01/2018 1:39:11 PM\n Asset Size Chunks Chunk Names\n dist/app.controller.d.ts 177 bytes [emitted] \n dist/app.module.d.ts 35 bytes [emitted] \n dist/app.service.d.ts 56 bytes [emitted] \n dist/main.d.ts 11 bytes [emitted] \n dist/main.hmr.d.ts 11 bytes [emitted] \n server.js 39 KiB main [emitted] main\n Entrypoint main = server.js\n [0] multi webpack/hot/poll?1000 ./src/main.hmr.ts 40 bytes {main} [built]\n [./node_modules/webpack/hot/log-apply-result.js] (webpack)/hot/log-apply-result.js 1.27 KiB {main} [built]\n [./node_modules/webpack/hot/log.js] (webpack)/hot/log.js 1.11 KiB {main} [built]\n [./node_modules/webpack/hot/poll.js?1000] (webpack)/hot/poll.js? 1000 1.15 KiB {main} [built]\n [./src/app.controller.ts] 1.44 KiB {main} [built]\n [./src/app.module.ts] 1.03 KiB {main} [built]\n [./src/app.service.ts] 883 bytes {main} [built]\n [./src/main.hmr.ts] 1.07 KiB {main} [built]\n [@nestjs/common] external "@nestjs/common" 42 bytes {main} [built]\n [@nestjs/core] external "@nestjs/core" 42 bytes {main} [built]\n gabriel@roraima-tv:/var/www/studying/tera-ping-pong$ \nRun Code Online (Sandbox Code Playgroud)\n\n因此,每当我添加 *.ts 文件更改时,它们在服务器重新启动之前不会重新加载。
\nAch*_*aul 12
您可以在监视模式下运行 Nest
nest start --watch
Run Code Online (Sandbox Code Playgroud)
小智 4
首先安装所需的包:
npm i --save-dev webpack-node-externals start-server-webpack-plugin
Run Code Online (Sandbox Code Playgroud)
安装完成后,在应用程序的根目录中创建一个 webpack-hmr.config.js 文件。
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 }),
],
};
};
Run Code Online (Sandbox Code Playgroud)
要启用HMR,请打开应用程序入口文件(main.ts)并添加以下webpack相关指令:
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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15574 次 |
| 最近记录: |