Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Webpack HMR for Node.js

I use webpack to bundle my nodejs code. As well known, we could use webpack-dev-server to build an environment for dev, so how about nodejs? I know nodemon can work, but it restart the whole project, I want a HMR way.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can follow this:

  1. run npm i --save-dev webpack-node-externals run-script-webpack-plugin webpack
  2. create a webpack-hmr.config.js file in the root directory of your application and put this:

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 }),
    ],
  };
};
  1. inside your main.js:
async function bootstrap() {
  <Your Express middleware and etc>
  if (module.hot) {
    module.hot.accept();
    module.hot.dispose(() => server.close());
  }
}

inspired by Nest.js HMR

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!