簡體   English   中英

webpack dev中間件,如何在HMR失敗時自動重載

[英]webpack dev middleware, how to autoreload when HMR fails

當我更改我的javascript源時,我在瀏覽器的控制台中收到以下消息:

[HMR]以下模塊無法熱更新:(需要完全重新加載)這通常是因為已更改的模塊(及其父級)不知道如何熱重新加載自己。 有關詳細信息,請參閱http://webpack.github.io/docs/hot-module-replacement-with-webpack.html

我的問題是,如果發生這種情況,我怎么能告訴webpack只是自動重新加載頁面?

這是我的服務器設置:

app.use(morgan('dev'));

        // Disable views cache
        app.set('view cache', false);

        var webpack = require('webpack');

        var webpackConfig = require('../client/webpack.config');
        var compiler = webpack(webpackConfig);

        app.use(require("webpack-dev-middleware")(compiler, {
            noInfo: true, publicPath: webpackConfig.output.publicPath
        }));
        app.use(require("webpack-hot-middleware")(compiler));

和我的webpack.config:

var path = require('path');
var AureliaWebpackPlugin = require('../node_modules/aurelia-webpack-plugin');
var webpack = require('../node_modules/webpack');

module.exports = {
    entry: {
        main: [
            'webpack-hot-middleware/client',
            './client/src/main'
        ]
    },
    resolve: {
        alias: {
            breeze: 'breeze-client/build/breeze.debug',
            resources: path.resolve( __dirname, 'src', 'resources'),
            utils: path.resolve( __dirname, 'src', 'resources', 'utils', 'utils'),
            tradestudyUtils: path.resolve( __dirname, 'src', 'resources', 'tradestudy-utils', 'tradestudy-utils')
        }
    },
    output: {
        path: path.join(__dirname, 'client'),
        filename: 'bundle.js',
        publicPath: '/'
    },
    devtool: 'eval',
    plugins: [
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        new AureliaWebpackPlugin()
    ],
    module: {
        //preLoaders: [
        //    {test: /\.js$/, exclude: /node_modules/, loader: 'eslint-loader'}
        //],
        loaders: [
            { test: /\.scss$/, loaders: ['style', 'css', 'sass'] },
            { test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: { presets: ['es2015-loose', 'stage-1'], plugins: ['transform-decorators-legacy'] } },
            { test: /\.css?$/, loader: 'style!css' },
            { test: /\.html$/, loader: 'raw' },
            { test: /\.(png|gif|jpg)$/, loader: 'url-loader?limit=8192' },
            { test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff2' },
            { test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
            { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' }
        ]
    }
};

提前致謝?

您可以將參數 reloadwebpack-hot-middleware/client

    entry: {
        main: [
            'webpack-hot-middleware/client?reload=true',
            './client/src/main'
        ]
    },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM