webpack / docs

[OLD] documentation for webpack
http://webpack.github.io/docs/
1.46k stars 127 forks source link

following doc on hot module replacement does not work #97

Closed andrixb closed 7 years ago

andrixb commented 7 years ago

Hello everybody,

I've been smashing my head around for quite a while since I'm not able to see the HMR working properly. The console shows the HMR activities (such as listening, and file changing), but eventually updates are not displayed.

I'm using this config:

...
const config = {
    entry: [
        'webpack-dev-server/client?http://localhost:8080',
        // // bundle the client for webpack-dev-server
        // // and connect to the provided endpoint
        //
        'webpack/hot/only-dev-server',
        // bundle the client for hot reloading
        // only- means to only hot reload for successful updates
        './src/index.js',
    ],
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].bundle.js',
        publicPath: 'http://localhost:8080/',
        hotUpdateChunkFilename: 'hot/hot-update.js',
        hotUpdateMainFilename: 'hot/hot-update.json',
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: [
                    path.resolve(__dirname, 'node_modules'),
                ],
                loader: 'babel-loader',
                options: {
                    presets: ['react', 'es2015', 'stage-2'],
                },
            },
            {
                test: /\.s(a|c)ss$/,
                loader: extractSCSS.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'postcss-loader', 'sass-loader'],
                }),
            },
            {
                test: /\.css$/,
                loader: extractCSS.extract({
                    fallback: 'style-loader',
                    use: ['css-loader', 'postcss-loader'],
                }),
            },
        ],
    },
    plugins: [
        extractCSS,
        extractSCSS,
        HotModuleReplacementPlugin,
        NamedModulesPlugin,
        NoEmitOnErrorsPlugin,
    ],

    devtool: 'inline-source-map',
    devServer: {
        publicPath: 'http://localhost:8080/',
        contentBase: './',
        inline: true,
        hot: true,
        port: 8080,
        historyApiFallback: true
    },
};

and I'm using this API in a test module:

if (module.hot) {
    module.hot.accept();
}

Could you please help me to sort this out? Thanks

andrixb commented 7 years ago

It's webpack 2 issue. Moving this question in https://github.com/webpack/webpack.js.org/issues/990