fix:加载优化
This commit is contained in:
parent
31d56dd18a
commit
3c4f26262e
@ -96,11 +96,12 @@
|
|||||||
"@vue/cli-service": "4.4.6",
|
"@vue/cli-service": "4.4.6",
|
||||||
"babel-eslint": "10.1.0",
|
"babel-eslint": "10.1.0",
|
||||||
"chalk": "4.1.0",
|
"chalk": "4.1.0",
|
||||||
|
"compression-webpack-plugin": "6.x",
|
||||||
"connect": "3.6.6",
|
"connect": "3.6.6",
|
||||||
"eslint": "7.15.0",
|
"eslint": "7.15.0",
|
||||||
"eslint-plugin-vue": "7.2.0",
|
"eslint-plugin-vue": "7.2.0",
|
||||||
"prettier": "^3.4.2",
|
|
||||||
"lint-staged": "10.5.3",
|
"lint-staged": "10.5.3",
|
||||||
|
"prettier": "^3.4.2",
|
||||||
"runjs": "4.4.2",
|
"runjs": "4.4.2",
|
||||||
"sass": "1.32.13",
|
"sass": "1.32.13",
|
||||||
"sass-loader": "10.1.1",
|
"sass-loader": "10.1.1",
|
||||||
|
@ -7,7 +7,7 @@ import { getToken } from '@/utils/auth';
|
|||||||
|
|
||||||
NProgress.configure({ showSpinner: false });
|
NProgress.configure({ showSpinner: false });
|
||||||
|
|
||||||
const whiteList = ['/login', '/auth-redirect', '/bind', '/register', '/preview'];
|
const whiteList = ['/login', '/auth-redirect', '/bind', '/register', '/preview', '/dataV'];
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
NProgress.start();
|
NProgress.start();
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
const path = require('path')
|
const path = require('path');
|
||||||
|
const CompressionWebpackPlugin = require('compression-webpack-plugin');
|
||||||
|
|
||||||
function resolve(dir) {
|
function resolve(dir) {
|
||||||
return path.join(__dirname, dir)
|
return path.join(__dirname, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = process.env.VUE_APP_TITLE || '智慧农业智能控制系统' // 网页标题
|
const name = process.env.VUE_APP_TITLE || '智慧农业智能控制系统'; // 网页标题
|
||||||
|
|
||||||
const port = process.env.VUE_PORT || process.env.npm_config_port || 80 // 端口
|
const port = process.env.VUE_PORT || process.env.npm_config_port || 80; // 端口
|
||||||
// vue.config.js 配置说明
|
// vue.config.js 配置说明
|
||||||
// 官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
|
// 官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
|
||||||
// 这里只列一部分,具体配置参考文档
|
// 这里只列一部分,具体配置参考文档
|
||||||
@ -35,32 +36,40 @@ module.exports = {
|
|||||||
target: process.env.VUE_APP_SERVER_API_URL,
|
target: process.env.VUE_APP_SERVER_API_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
pathRewrite: {
|
pathRewrite: {
|
||||||
['^' + process.env.VUE_APP_BASE_API]: ''
|
['^' + process.env.VUE_APP_BASE_API]: '',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
'/api/v4': {
|
'/api/v4': {
|
||||||
target: process.env.VUE_APP_EMQX_API_URL,
|
target: process.env.VUE_APP_EMQX_API_URL,
|
||||||
changeOrigin: true
|
changeOrigin: true,
|
||||||
// logLevel: 'debug',
|
// logLevel: 'debug',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
https: false,
|
https: false,
|
||||||
disableHostCheck: true
|
disableHostCheck: true,
|
||||||
},
|
},
|
||||||
configureWebpack: {
|
configureWebpack: {
|
||||||
name: name,
|
name: name,
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve('src')
|
'@': resolve('src'),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
|
plugins: [
|
||||||
|
// 开启 Gzip 压缩
|
||||||
|
new CompressionWebpackPlugin({
|
||||||
|
test: /\.(js|css|html|svg)$/,
|
||||||
|
threshold: 10240,
|
||||||
|
minRatio: 0.8,
|
||||||
|
}),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
chainWebpack(config) {
|
chainWebpack(config) {
|
||||||
config.plugins.delete('preload') // TODO: need test
|
config.plugins.delete('preload'); // TODO: need test
|
||||||
config.plugins.delete('prefetch') // TODO: need test
|
config.plugins.delete('prefetch'); // TODO: need test
|
||||||
|
|
||||||
// set svg-sprite-loader
|
// set svg-sprite-loader
|
||||||
config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end()
|
config.module.rule('svg').exclude.add(resolve('src/assets/icons')).end();
|
||||||
config.module
|
config.module
|
||||||
.rule('icons')
|
.rule('icons')
|
||||||
.test(/\.svg$/)
|
.test(/\.svg$/)
|
||||||
@ -69,9 +78,9 @@ module.exports = {
|
|||||||
.use('svg-sprite-loader')
|
.use('svg-sprite-loader')
|
||||||
.loader('svg-sprite-loader')
|
.loader('svg-sprite-loader')
|
||||||
.options({
|
.options({
|
||||||
symbolId: 'icon-[name]'
|
symbolId: 'icon-[name]',
|
||||||
})
|
})
|
||||||
.end()
|
.end();
|
||||||
|
|
||||||
config.when(process.env.NODE_ENV !== 'development', (config) => {
|
config.when(process.env.NODE_ENV !== 'development', (config) => {
|
||||||
config
|
config
|
||||||
@ -80,10 +89,11 @@ module.exports = {
|
|||||||
.use('script-ext-html-webpack-plugin', [
|
.use('script-ext-html-webpack-plugin', [
|
||||||
{
|
{
|
||||||
// `runtime` must same as runtimeChunk name. default is `runtime`
|
// `runtime` must same as runtimeChunk name. default is `runtime`
|
||||||
inline: /runtime\..*\.js$/
|
inline: /runtime\..*\.js$/,
|
||||||
}
|
},
|
||||||
])
|
])
|
||||||
.end()
|
.end();
|
||||||
|
|
||||||
config.optimization.splitChunks({
|
config.optimization.splitChunks({
|
||||||
chunks: 'all',
|
chunks: 'all',
|
||||||
cacheGroups: {
|
cacheGroups: {
|
||||||
@ -91,28 +101,29 @@ module.exports = {
|
|||||||
name: 'chunk-libs',
|
name: 'chunk-libs',
|
||||||
test: /[\\/]node_modules[\\/]/,
|
test: /[\\/]node_modules[\\/]/,
|
||||||
priority: 10,
|
priority: 10,
|
||||||
chunks: 'initial' // only package third parties that are initially dependent
|
chunks: 'initial', // only package third parties that are initially dependent
|
||||||
},
|
},
|
||||||
elementUI: {
|
elementUI: {
|
||||||
name: 'chunk-elementUI', // split elementUI into a single package
|
name: 'chunk-elementUI', // split elementUI into a single package
|
||||||
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
||||||
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
|
test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
|
||||||
},
|
},
|
||||||
commons: {
|
commons: {
|
||||||
name: 'chunk-commons',
|
name: 'chunk-commons',
|
||||||
test: resolve('src/components'), // can customize your rules
|
test: resolve('src/components'), // can customize your rules
|
||||||
minChunks: 3, // minimum common number
|
minChunks: 3, // minimum common number
|
||||||
priority: 5,
|
priority: 5,
|
||||||
reuseExistingChunk: true
|
reuseExistingChunk: true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line no-sequences
|
// eslint-disable-next-line no-sequences
|
||||||
config.optimization.runtimeChunk('single'),
|
config.optimization.runtimeChunk('single'),
|
||||||
{
|
{
|
||||||
from: path.resolve(__dirname, './public/robots.txt'), // 防爬虫文件
|
from: path.resolve(__dirname, './public/robots.txt'), // 防爬虫文件
|
||||||
to: './' // 到根目录下
|
to: './', // 到根目录下
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user