禁用webpack热重载功能

3
我正在配置简单的Webpack堆栈,并且它可以工作,但问题是每次文件更改时都会重新加载应用程序。有没有办法关闭每个文件更改时的重新加载?我想手动重新加载页面,我也不使用热重新加载,也不想使用它。
对于服务器,我正在使用文件:
/*eslint no-console:0 */
'use strict';
require('core-js/fn/object/assign');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
const open = require('open');

new WebpackDevServer(webpack(config), config.devServer)
.listen(config.port, 'localhost', (err) => {
  if (err) {
    console.log(err);
  }
  console.log('Listening at localhost:' + config.port);
  console.log('Opening your system browser...');
  open('http://localhost:' + config.port + '/webpack-dev-server/');
});

对于webpack配置,以下是一些部分:

module.exports = {
  additionalPaths: additionalPaths,
  port: defaultSettings.port,
  debug: true,
  devtool: 'eval',
  output: {
    path: path.join(__dirname, '/../dist'),
    filename: '[name].js',
    publicPath: defaultSettings.publicPath
  },
  devServer: {
    contentBase: './src/',
    historyApiFallback: true,
    hot: false,
    port: defaultSettings.port,
    publicPath: defaultSettings.publicPath,
    noInfo: false
  },
  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
      plugins: `${defaultSettings.srcPath}/../plugins`,
      core: `${defaultSettings.srcPath}/../core`
    }
  }
};

以及开发者配置:

let config = Object.assign({}, baseConfig, {
  entry: {
    start: ['./src/index'],
    vendors: [],
    core: './plugins/lunchbadger-core/index',
    plugins: infoFile.plugins.map((plugin) => { return ('./plugins/lunchbadger-' + plugin); })
  },
  cache: true,
  devtool: 'eval',
  plugins: [
    new webpack.NoErrorsPlugin()
  ],
  module: defaultSettings.getDefaultModules()
});
2个回答

1

这是一个有些老旧的问题,但我认为现在可以使用 webpack-dev-server --liveReload false 来解决。


还可以在angular.json文件中的architect > serve > options > liveReload位置找到选项。 - Xriuk

1
也许解决方案是在这种情况下跳过webpack-dev-server,而是使用监视模式运行webpack(webpack --watch)?监视模式将在检测到更改时重新编译您的文件。在这种情况下,您需要单独提供站点(例如使用serve),但这个组合可以实现您想要的效果。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接