React项目中热更新问题

南农肉松 发布于 2018/04/28 15:45
阅读 1K+
收藏 0

配置文件:

const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    devtool: 'false',
    entry: __dirname + "/public/js/index.js",
    output: {
        path: __dirname + "/build",
        filename: "bundle.js"
    },
    devServer: {
        historyApiFallback: true,
        inline: true,
        hot: true,
        stats: {
            colors: true
        }
    },
    module: {
        rules: [
            {
                test: /(\.jsx|\.js)$/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        cacheDirectory: true,
                        presets: [
                            'env', 'react'
                        ],
                        env: {
                            development: {
                                plugins: [["react-transform", {
                                    "transforms": [{
                                        "transform": "react-transform-hmr",
                                        "imports": ["react"],
                                        "locals": ["module"]
                                    }]
                                }]]
                            }
                        },
                        plugins: ['transform-runtime', 'transform-class-properties', ["import", { libraryName: "antd-mobile", style: "css" }]]
                    }
                },
                exclude: /node_modules/
            },
            {
                test: /\.css$/,
                exclude: /(node_modules)/,
                use: [
                    'style-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            modules: true,
                            localIdentName: '[name]__[local]',
                        }
                    }
                ]
            },
            {
                test: /\.css$/,
                exclude: /(public)/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: '[name].[ext]',
                },
            },
            {
                test: /\.mp3$/,
                loader: 'file-loader',
                options: {
                    name: '[name].[ext]'
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: __dirname + "/public/index.html"
        }),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new ExtractTextPlugin("style.css")
    ]
}

我直接打包  webpack,耗时约4s,速度还能接受吧.....

但是我用webpack-dev-server做热更新跑起来,打包一次要20s,这是什么鬼.....

请大家帮我看一下,谢谢!

加载中
0
南农肉松
南农肉松
module.exports = {
   //...
   mode: 'development'
   //...
}
返回顶部
顶部