用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: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",
PHPz2017-04-17 16:32:17
投稿者の問題は、以前に babel-loader
がサードパーティのクラス ライブラリをコンパイルしたことが原因でした。投稿者は exclude
を使用して生成することをお勧めします。それが正しいかどうかを確認するための分析チャート。私服チームを必要としないサードパーティ ライブラリがコンパイルされていますwebpack-bundle-analyzer
。