Skip to content

Commit

Permalink
Feat: bundle size optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
LanceZhu committed Nov 26, 2019
1 parent f6d152a commit dad4c13
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"serve:education": "vue-cli-service serve --mode education",
"serve:invention": "vue-cli-service serve --mode invention",
"build": "vue-cli-service build",
"build:internet": "vue-cli-service build --mode internet",
"build:education": "vue-cli-service build --mode education",
"build:invention": "vue-cli-service build --mode invention",
"lint": "vue-cli-service lint"
"build:internet": "NODE_ENV='production' vue-cli-service build --mode internet",
"build:education": "NODE_ENV='production' vue-cli-service build --mode education",
"build:invention": "NODE_ENV='production' vue-cli-service build --mode invention",
"lint": "vue-cli-service lint",
"analyzer": "ANALYZER=true vue-cli-service serve"
},
"dependencies": {
"axios": "^0.19.0",
Expand All @@ -38,7 +39,8 @@
"eslint-plugin-vue": "^5.0.0",
"quill-image-extend-module": "^1.1.2",
"terser-webpack-plugin": "^2.2.1",
"vue-template-compiler": "^2.6.10"
"vue-template-compiler": "^2.6.10",
"webpack-bundle-analyzer": "^3.6.0"
},
"eslintConfig": {
"root": true,
Expand Down
3 changes: 2 additions & 1 deletion src/page/timepoint/add.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ import { Quill } from 'vue-quill-editor'
import { container, ImageExtend, QuillWatch } from 'quill-image-extend-module'
import config from '../../../config'
import dayjs from 'dayjs'
import { clone } from 'lodash'
// import { clone } from 'lodash'
import clone from 'lodash/clone'
Quill.register('modules/ImageExtend', ImageExtend)
Expand Down
3 changes: 2 additions & 1 deletion src/page/timepoint/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ import { container, ImageExtend, QuillWatch } from 'quill-image-extend-module'
import config from '../../../config'
import dayjs from 'dayjs'
// import isJSON from '@/utils/isJSON'
import { clone } from 'lodash'
// import { clone } from 'lodash'
import clone from 'lodash/clone'
Quill.register('modules/ImageExtend', ImageExtend)
Expand Down
26 changes: 24 additions & 2 deletions vue.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
// import config from './config.js'
// const UglifyPlugin = require('uglifyjs-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const BundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

// webpack 插件
const webpackPlugins = []
if(process.env.ANALYZER){
webpackPlugins.push(new BundleAnalyzer())
}

// webpack 打包优化插件
const minimizers = []
if(process.env.NODE_ENV === 'production'){
minimizers.push(new TerserPlugin({
terserOptions: {
ecma: 6,
compress: { drop_console: true },
output: { comments: false, beautify: false }
},
extractComments: false
}))
}

const path = require('path')
function resolve (dir) {
Expand All @@ -11,15 +31,17 @@ module.exports = {
publicPath: '',
outputDir: 'dist',
runtimeCompiler: true,
productionSourceMap: false,
configureWebpack: {
plugins: [],
plugins: webpackPlugins,
resolve: {
alias: {
'@': resolve('src')
}
},
optimization: {
minimizer: [new TerserPlugin()]
minimize: true,
minimizer: minimizers
}
},
devServer: {
Expand Down

0 comments on commit dad4c13

Please sign in to comment.