Authored by shijian

web pack性能提优

... ... @@ -146,3 +146,4 @@ public/bundle/*
nbproject/*
.DS_Store
.devhost
.happypack/
\ No newline at end of file
... ...
... ... @@ -31,6 +31,7 @@
"express": "^4.14.0",
"express-session": "^1.14.1",
"handlebars-loader": "^1.5.0",
"happypack": "^3.1.0",
"influxdb-winston": "^1.0.1",
"lodash": "^4.15.0",
"memcached": "^2.2.1",
... ... @@ -46,6 +47,7 @@
"vue-loader": "^8.3.0",
"vue-template-compiler": "^2.3.3",
"webpack-uglify-parallel": "^0.1.3",
"webpack-visualizer-plugin": "^0.1.11",
"winston": "^2.2.0",
"winston-daily-rotate-file": "^1.3.0",
"yoho-jquery": "^2.2.4",
... ...
... ... @@ -3,6 +3,24 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpack = require('webpack');
const shelljs = require('shelljs');
const _ = require('lodash');
const HappyPack = require('happypack');
const os = require('os');
const happyThreadPool = HappyPack.ThreadPool({ // eslint-disable-line
size: os.cpus().length
});
const hbsLoader = {
loader: 'handlebars-loader',
options: {
helperDirs: [
path.join(__dirname, '../js/common/helpers')
],
partialDirs: [
path.join(__dirname, '../../doraemon/views/partial')
]
}
};
const getEntries = () => {
const entries = {
... ... @@ -59,7 +77,7 @@ module.exports = {
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader'
loader: 'happypack/loader?id=js'
}
}, {
test: /\.css$/,
... ... @@ -76,19 +94,21 @@ module.exports = {
}, {
test: /\.hbs$/,
use: [{
loader: 'handlebars-loader',
options: {
helperDirs: [
path.join(__dirname, '../js/common/helpers')
],
partialDirs: [
path.join(__dirname, '../../doraemon/views/partial')
]
}
loader: 'happypack/loader?id=hbs'
}]
}]
},
plugins: [
new HappyPack({
id: 'js',
threadPool: happyThreadPool,
loaders: ['babel-loader'],
}),
new HappyPack({
id: 'hbs',
threadPool: happyThreadPool,
loaders: [hbsLoader]
}),
new ExtractTextPlugin('[name].css'),
new webpack.optimize.CommonsChunkPlugin({
names: 'libs'
... ...
... ... @@ -2,6 +2,7 @@ const merge = require('webpack-merge');
const webpack = require('webpack');
const path = require('path');
const devInfo = require('./dev-info.js');
var Visualizer = require('webpack-visualizer-plugin');
module.exports = merge(require('./webpack.base.config'), {
... ... @@ -10,7 +11,10 @@ module.exports = merge(require('./webpack.base.config'), {
path: path.resolve(__dirname, 'bundle')
},
plugins: [
new webpack.HotModuleReplacementPlugin()
new webpack.HotModuleReplacementPlugin(),
new Visualizer({
filename: './statistics.html'
})
],
devServer: {
contentBase: [path.join(__dirname, '../')],
... ...