项目根目录创建webpack.dll.conf.js
const path = require('path')
const webpack = require('webpack')
module.exports = {
entry: {
vender: ['vue', 'vue-router', 'axios', 'vuex']
},
output: {
path: path.join(__dirname, '../public/static'),
filename: "[name].dll.js",
library: "[name]_library"
},
plugins: [
new webpack.DllPlugin({
path: path.join(__dirname, ".", "[name]-manifest.json"),
name: "[name]_library"
})
]
}
vue.config.js 配置
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const webpack = require('webpack')
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
const CompressionPlugin = require("compression-webpack-plugin")
const isProduction = process.env.NODE_ENV === 'production'
const name = '大数据人才库'
const resolve = (dir) => path.join(__dirname, dir)
module.exports = {
outputDir: 'front',
lintOnSave: true,
productionSourceMap: false,
devServer: {
hot: true,
proxy: {
'/gov_api': {
target: 'http://gov_rck.yunzedd.com/'
},
'/api': {
target: 'http://gov_rck.yunzedd.com/'
}
}
},
css: {
loaderOptions: {
sass: {
prependData: `@import "styles/vars.scss";`
}
}
},
chainWebpack: config => {
config.resolve.alias
.set('apis', resolve('src/apis'))
.set('comps', resolve('src/components'))
.set('views', resolve('src/views'))
.set('styles', resolve('src/styles'))
.set('imgs', resolve('src/assets/images'))
.set('utils', resolve('src/utils'))
if (isProduction) {
config.module
.rule('images')
.use('image-webpack-loader')
.loader('image-webpack-loader')
.options({ bypassOnDebug: true })
.end()
}
},
configureWebpack: config => {
config.name = name
if (isProduction) {
config.plugins.push(new webpack.DllReferencePlugin({
context: process.cwd(),
manifest: require('./build/vender-manifest.json')
}))
config.plugins.push(
new AddAssetHtmlPlugin({
filepath: path.resolve(__dirname, './public/static/vender.dll.js'),
publicPath: './static',
outputPath: './static',
})
)
config.optimization = {
splitChunks: {
chunks: 'all',
cacheGroups: {
'vendors': {
test: /[\\/]node_modules[\\/]/,
priority: -20
},
'element-ui': {
name: 'element-ui',
test: /[\\/]node_modules[\\/]element-ui[\\/]/,
priority: -10
},
'echarts': {
name: 'echarts',
test: /[\\/]node_modules[\\/]echarts[\\/]/,
priority: -10
},
'element-china-area-data': {
name: 'element-china-area-data',
test: /[\\/]node_modules[\\/]element-china-area-data[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
}
config.plugins.push(
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ['console.log', 'console.error']
}
}
})
)
return {
plugins: [
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i,
threshold: 10240,
minRatio: 0.8,
})
]
}
}
}
}
项目根目录创建deploy.sh
#!/bin/bash
tar -zcvf admin-talent-pool.tar.gz front
echo "[文件压缩完成!]"
scp admin-talent-pool.tar.gz root@39.101.180.5:/data/gov_rck
echo "[文件上传完成完成!]"
ssh root@39.101.180.5 << remotessh
cd /data/gov_rck
rm -rf front
mkdir front
tar -zxvf admin-talent-pool.tar.gz -C /data/gov_rck
rm -rf admin-talent-pool.tar.gz
exit
remotessh
rm -rf admin-talent-pool.tar.gz
echo "[删除本地压缩包!]"
package.json 下的scripts
"deploy": "yarn dll && yarn build && sh deploy.sh"