Commit 54d4394b by lijiabin

【优化】 perf: 打包优化,非首屏加载资源并且文件较大则改为动态加载

parent a1251cdc
import * as XLSX from 'xlsx'
import { push } from 'notivue'
/**
* 导出 Excel
......@@ -21,13 +20,15 @@ export interface ExportOptions<T> {
sheetName?: string
}
export function exportExcel<T>({
export async function exportExcel<T>({
data,
columns,
fileName = '导出数据',
sheetName = 'Sheet1',
}: ExportOptions<T>) {
if (!data || !data.length) return push.warning('没有可导出的数据')
// 文件比较大 切非首屏加载 可以选择动态引入 避免首屏加载过慢
const XLSX = await import('xlsx')
const header = columns.map((col) => col.title)
......
import CryptoJS from 'crypto-js'
/**
* 使用 MD5 加密字符串
* @param input - 要加密的字符串
* @returns 加密后的 MD5 字符串
*/
export function md5Hash(input: string): string {
return CryptoJS.MD5(input).toString()
}
/**
* AES 加密方法
* @param plaintext 要加密的明文
* @param key 密钥 (16, 24 或 32 字节长度的字符串)
* @returns 加密后的字符串
*/
export function aesEncrypt(plaintext: string, key: string): string {
if (![16, 24, 32].includes(key.length)) {
throw new Error('秘钥长度必须为 16, 24 或 32 字节。')
}
// 加密数据
const encrypted = CryptoJS.AES.encrypt(plaintext, CryptoJS.enc.Utf8.parse(key), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})
return encrypted.toString()
}
......@@ -82,7 +82,8 @@ export default defineConfig(({ mode }) => {
// },
},
build: {
minify: true, // 'esbuild'
minify: true,
// minify: false,
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
......@@ -90,9 +91,12 @@ export default defineConfig(({ mode }) => {
chunkFileNames: 'assets/js/[name]-[hash].js',
codeSplitting: {
groups: [
{ name: 'elementPlus-vendor', test: /node_modules[\\/]element-plus/, priority: 9 },
{ name: 'vue-vendor', test: /node_modules[\\/]vue/, priority: 10 },
{ name: 'elementPlus-vendor', test: /node_modules[\\/]element-plus/, priority: 9 },
{ name: 'wangeditor-vendor', test: /node_modules[\\/]@wangeditor/, priority: 8 },
{ name: 'xlsx-vendor', test: /node_modules[\\/]xlsx/, priority: 7 },
{ name: 'crypto-js-vendor', test: /node_modules[\\/]crypto-js/, priority: 6 },
{ name: 'vue-use-vendor', test: /node_modules[\\/]@vueuse/, priority: 5 },
{
name: 'common',
minShareCount: 2,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment