From d38339825012c3c84dc1c63dac718245f98c47aa Mon Sep 17 00:00:00 2001 From: FairyEver <1711467488@qq.com> Date: Thu, 12 Dec 2019 20:09:31 +0800 Subject: [PATCH] runtime Former-commit-id: 856ffa599cba540197ec393598942809a3925e72 Former-commit-id: 460b39488f790611ddcff9b9632998a7e7dc6f88 Former-commit-id: 686bc89bc486bd217edc7066ee8dfc8ad24c0bd0 Former-commit-id: 4700849c0fec1e54ffb2bfa23e911b06ef0e32be [formerly 2b43f432b96bc78b7714ac46135c168d8666353b] Former-commit-id: 3e304a0514c9f0e0af71e8849d304d246b8811e2 Former-commit-id: dd95fa3d67c0220dce2844e48e19daa4d556e496 Former-commit-id: 765eec344db78fe509e57aaeaae8e8ed7b272a52 Former-commit-id: ceb73b8ba61f1645ccd5d89bbd585cc50c214011 Former-commit-id: 9c66c63cad2cbd448a4349e00495e2af8569b57d --- package-lock.json.REMOVED.git-id | 2 +- package.json | 4 +++ vue.config.js | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/package-lock.json.REMOVED.git-id b/package-lock.json.REMOVED.git-id index 9f57a3ba..81b6cd91 100644 --- a/package-lock.json.REMOVED.git-id +++ b/package-lock.json.REMOVED.git-id @@ -1 +1 @@ -975a87cbfa94ae0055fa5dbbf387398b44b8c8f0 \ No newline at end of file +d5b6db76fb2766c6c4500653fe9988f046835785 \ No newline at end of file diff --git a/package.json b/package.json index bcd7eecb..8df31257 100644 --- a/package.json +++ b/package.json @@ -64,10 +64,14 @@ "compression-webpack-plugin": "^3.0.1", "eslint": "^5.16.0", "eslint-plugin-vue": "^5.2.2", + "html-webpack-plugin": "^3.2.0", + "inline-manifest-webpack-plugin": "^4.0.2", + "optimize-css-assets-webpack-plugin": "^5.0.3", "sass": "^1.21.0", "sass-loader": "^7.1.0", "svg-sprite-loader": "^4.1.6", "text-loader": "0.0.1", + "uglifyjs-webpack-plugin": "^2.2.0", "vue-cli-plugin-i18n": "^0.6.0", "vue-template-compiler": "^2.6.10", "webpack-theme-color-replacer": "^1.2.15" diff --git a/vue.config.js b/vue.config.js index e28e1592..c2ffaaf6 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,5 +1,11 @@ const CompressionWebpackPlugin = require('compression-webpack-plugin') +const UglifyJsPlugin = require('uglifyjs-webpack-plugin') +const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin') + +const HtmlWebpackPlugin = require('html-webpack-plugin') +const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin') + const VueFilenameInjector = require('@d2-projects/vue-filename-injector') const ThemeColorReplacer = require('webpack-theme-color-replacer') @@ -31,7 +37,53 @@ module.exports = { } }, configureWebpack: { + optimization: { + runtimeChunk: 'single', + minimizer: [ + // 自定义js优化配置,将会覆盖默认配置 + new UglifyJsPlugin({ + exclude: /\.min\.js$/, // 过滤掉以".min.js"结尾的文件,我们认为这个后缀本身就是已经压缩好的代码,没必要进行二次压缩 + cache: true, + parallel: true, // 开启并行压缩,充分利用cpu + sourceMap: false, + extractComments: false, // 移除注释 + uglifyOptions: { + compress: { + unused: true, + drop_debugger: true + }, + output: { + comments: false + }, + warnings: false + } + }), + // 用于优化css文件 + new OptimizeCssAssetsPlugin({ + assetNameRegExp: /\.css$/g, + cssProcessorOptions: { + safe: true, + autoprefixer: { disable: true }, + mergeLonghand: false, + discardComments: { + removeAll: true // 移除注释 + } + }, + canPrint: true + }) + ] + }, plugins: [ + // runtime 相关的代码嵌入 indexe.html + new HtmlWebpackPlugin({ + title: 'fle-cli', + filename: 'index.html', + inject: true, + chunks: ['runtime', 'app'], + chunksSortMode: 'dependency', + minify: {/* */} + }), + new InlineManifestWebpackPlugin('runtime'), // gzip new CompressionWebpackPlugin({ filename: '[path].gz[query]',