/* eslint-disable @typescript-eslint/no-var-requires */
const webpackNodeExternals = require('webpack-node-externals');
const {
  RunScriptWebpackPlugin: WebpackRunScriptPlugin,
} = require('run-script-webpack-plugin');

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