File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 5555 "babel-plugin-dynamic-import-node" : " 2.3.3" ,
5656 "chalk" : " 2.4.2" ,
5757 "chokidar" : " 2.1.5" ,
58+ "compression-webpack-plugin" : " ^3.1.0" ,
5859 "connect" : " 3.6.6" ,
5960 "eslint" : " 6.7.2" ,
6061 "eslint-plugin-vue" : " 6.2.2" ,
Original file line number Diff line number Diff line change 11'use strict'
22const path = require ( 'path' )
33const defaultSettings = require ( './src/settings.js' )
4-
4+ const webpackPlugins = [ ]
5+ if ( process . env . NODE_ENV === 'production' ) {
6+ const CompressionPlugin = require ( 'compression-webpack-plugin' )
7+ webpackPlugins . push ( new CompressionPlugin ( {
8+ algorithm : 'gzip' ,
9+ test : / \. j s $ | \. h t m l $ | \. c s s $ | \. j p g $ | \. j p e g $ | \. p n g / , // 需要压缩的文件类型
10+ threshold : 10240 , // 归档需要进行压缩的文件大小最小值,我这个是10K以上的进行压缩
11+ deleteOriginalAssets : false , // 是否删除原文件
12+ minRatio : 0.5
13+ } ) )
14+ }
515function resolve ( dir ) {
616 return path . join ( __dirname , dir )
717}
@@ -46,7 +56,8 @@ module.exports = {
4656 alias : {
4757 '@' : resolve ( 'src' )
4858 }
49- }
59+ } ,
60+ plugins : webpackPlugins
5061 } ,
5162 chainWebpack ( config ) {
5263 // it can improve the speed of the first screen, it is recommended to turn on preload
@@ -88,7 +99,7 @@ module.exports = {
8899 . plugin ( 'ScriptExtHtmlWebpackPlugin' )
89100 . after ( 'html' )
90101 . use ( 'script-ext-html-webpack-plugin' , [ {
91- // `runtime` must same as runtimeChunk name. default is `runtime`
102+ // `runtime` must same as runtimeChunk name. default is `runtime`
92103 inline : / r u n t i m e \. .* \. j s $ /
93104 } ] )
94105 . end ( )
You can’t perform that action at this time.
0 commit comments