webpack热加载很慢

webpack的热加载文件在刚开始没几个的时候就快,但是加多了几个文件就变的很慢的,
随便改一个字都要6、7秒才能更新到
这是怎么回事?
这是我的启动dev-server

var path = require('path');
var fs = require('fs');
var express = require('express');
var webpack = require('webpack');
var routes = require('./router/index');
var config = require('./config');
var http = require('http');
var bodyParser = require('body-parser');
var compression = require('compression');
var consolidate = require('consolidate');
var webpackConfig = require('./webpack.dev.conf');

//端口
var port = process.env.PORT || config.dev.port;
var app = express();
//bodyparser 这个设置要放路由前原因:(http://blog.csdn.net/u013438638/article/details/48953143)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.engine('html', consolidate.ejs);
app.set('views', path.resolve(__dirname, 'views'));
app.set('view engine','html');
app.use(compression()); //开启 gzip

//webpack编译器
var compiler = webpack(webpackConfig);
//webpack-dev-server 中间件
var devMiddleware = require('webpack-dev-middleware')(compiler, {
    publicPath: webpackConfig.output.publicPath,
    stats: {
        colors: true,
        chunks: false
    }
});

//热更新中间件
var hotMiddleware = require('webpack-hot-middleware')(compiler);

app.use(devMiddleware);
app.use(hotMiddleware);

//具体路由action
routes(app);

webpack.dev.conf

var path = require('path');
var merge = require('webpack-merge');
var webpack = require('webpack');
var utils = require('./utils');
var HtmlWebpackPlugin = require('html-webpack-plugin');

var webpackConfig = {
    entry: {
        page: ['webpack-hot-middleware/client?noInfo=true&reload=true', '../resources/app/index.js']
    },
    devtool: 'source-map',
    output: {
        path: path.resolve(__dirname, './public'),
        publicPath: '/',
        filename: '[name].js'
    },
    module: {
        rules: [
            {test:/\.vue$/, loader: 'vue-loader'},
            {test:/\.html$/,loader: "html?attrs=img:src img:data-src"},
            {
                test:/\.css$/,
                use: ['style-loader',{
                    loader: 'css-loader'
                }]
            },
            {
                test: /\.scss$/,
                use: [
                    'style-loader',
                    'css-loader?sourceMap',
                    'resolve-url-loader',
                    'sass-loader?sourceMap'
                ]
            },
            {test:/\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,loader: 'file-loader?name=./fonts/[name].[ext]'},
            {test:/\.(png|jpe?g|gif|svg|webp)(\?.*)?$/,loader: 'url-loader?limit=10000&name=./images/[name].[ext]'},
            {test:/\.js$/, exclude: /(node_modules|lib)/, loader: 'babel-loader'}
        ]
    },
    plugins: [
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({
          'process.env': {
            NODE_ENV: '"production"'
          }
        }),
        new webpack.optimize.UglifyJsPlugin({
          compress: {
            warnings: false
          }
        })
    ],
    devServer: {
        inline: true
    }
}
module.exports = webpackConfig;

webpack.config.js

 "url-loader": "^0.5.8",
    "vue-hot-reload-api": "^2.0.11",
    "vue-html-loader": "^1.2.4",
    "vue-loader": "^11.3.4",
    "vue-style-loader": "^2.0.5",
    "vue-template-compiler": "^2.2.6",
    "webpack": "^2.3.3",
    "webpack-dev-middleware": "^1.10.1",
    "webpack-dev-server": "^2.4.2",
    "webpack-hot-middleware": "^2.18.0",
回复
阅读 11.6k
4 个回答

楼主的问题之前遇到过,是因为babel-loader编译了第三方类库导致的,我看了楼主已经exclude了,建议楼主用下 webpack-bundle-analyzer,生成分析图看下是不是编译了哪些不需要便衣队第三方的库

webpack.optimize.UglifyJsPlugin 开发阶段不需要压缩

请问楼主最终解决了么,优化手段是什么?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏