【问题标题】:Cannot find update. Need to do a full reload! in webpack找不到更新。需要完全重新加载!在 webpack 中
【发布时间】:2017-06-24 05:32:33
【问题描述】:

这是我的文件 webpack.config.js 。虽然我添加了['react-hot' ,'babel']。但是可以解决。

var webpack = require('webpack');
var path = require('path');
var APP_DIR = path.resolve(__dirname, 'client/');
var devFlagPlugin = new webpack.DefinePlugin({
    __DEV__: JSON.stringify(JSON.parse(process.env.DEBUG || 'true'))
});

var config = {
    cache: true,
    devtool: 'eval', // 'source-map', 'eval'
    entry: [
        'webpack-dev-server/client?http://localhost:3000/',
        'webpack/hot/only-dev-server',
        './client/app.jsx'
    ],
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js',
        publicPath: '/static/'
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                include: path.join(__dirname, 'client'),
                exclude: /node_modules/,
                loader: ['react-hot' ,'babel'],
                query: {
                    cacheDirectory: true,
                    presets: ['react', 'es2015']
                }
            },
            {
                test: /\.scss$/,
                loaders: ["style", "css", "sass"]
            },
            {
                test: /\.(jpe?g|png|gif|jpg|svg)$/i,
                loaders: [
                    'file?images/hash=sha512&digest=hex&name=../build/img/[hash].[ext]',
                    'image-webpack?{optimizationLevel: 9, interlaced: false, pngquant:{quality: "65-90", speed: 4}, mozjpeg: {quality: 65}}'
                ]
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                loader: 'file?name=../build/fonts/[name].[ext]'
            }
        ]
    },
    sassLoader: {
        includePaths: [path.resolve(__dirname, "./client/assets/css/")]
    },

    plugins: [
        devFlagPlugin,
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: true
            },
            output: {
                comments: true,
            }
        }), 
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ]

}

module.exports = config;

【问题讨论】:

    标签: javascript webpack ecmascript-6 react-hot-loader


    【解决方案1】:

    我相信您的问题是您需要使用 babel-preset-react-hmre 才能使其正常工作。更多信息在这里here。 例如

     {
        test: /\.jsx?$/,
        include: path.join(__dirname, 'client'),
        exclude: /node_modules/,
        loader: ['react-hot' ,'babel'],
        query: {
          cacheDirectory: true,
          presets: ['react', 'es2015', 'react-hmre']
         }
      },
    

    【讨论】:

    • 感谢您的帮助。但是我有新问题。””找不到模块:错误:无法解析模块'react-hot,babel' in . @multi main 我尝试在发表评论之前搜索,但仍然不能。
    • Paul - 为什么要修复它?您是怎么知道的?我没有在任何教程或文档中看到过这一点。
    猜你喜欢
    • 1970-01-01
    • 2019-10-25
    • 2016-10-03
    • 2018-12-20
    • 2013-10-31
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多