Skip to content

Commit

Permalink
处理图片压缩太费资源导致项目稍大热更新很慢,现已修改配置开发时禁用图片压缩可大大提升效率
Browse files Browse the repository at this point in the history
  • Loading branch information
givebest committed Oct 20, 2018
1 parent 366d3cc commit 5d4371b
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ if (IsProduction) {
}));
}

// 开发环境不压缩图片,提升热更新效率
let imageMin = [{
loader: 'url-loader',
options: {
limit: 100,
publicPath: publicPath + extraPath,
outputPath: function (path) {
return path.replace('src/img', 'img');
},
name: '[path][name].[ext]?[hash:8]'
}
}]
if (IsProduction) {
imageMin.push({
// @see https://github.com/tcoopman/image-webpack-loader
loader: 'image-webpack-loader',
query: {
mozjpeg: {
quality: 65
},
pngquant: {
quality: '65-90',
speed: 4
}
}
})
}

// 配置
const config = {
entry: entryJs,
Expand Down Expand Up @@ -142,32 +170,7 @@ const config = {
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 100,
publicPath: publicPath + extraPath,
outputPath: function (path) {
return path.replace('src/img', 'img');
},
name: '[path][name].[ext]?[hash:8]'
}
},
// @see https://github.com/tcoopman/image-webpack-loader
{
loader: 'image-webpack-loader',
query: {
mozjpeg: {
quality: 65
},
pngquant: {
quality: '65-90',
speed: 4
}
}
}
]
use: imageMin
},
{
test: /\.(eot|svg|ttf|woff)$/i,
Expand Down

0 comments on commit 5d4371b

Please sign in to comment.