xiaoxian521
2 years ago
11 changed files with 124 additions and 27 deletions
-
5.env.production
-
5.env.staging
-
63build/compress.ts
-
3build/index.ts
-
5build/plugins.ts
-
1package.json
-
18pnpm-lock.yaml
-
19src/views/permission/button/index.vue
-
15src/views/permission/page/index.vue
-
10types/global.d.ts
-
3vite.config.ts
@ -0,0 +1,63 @@ |
|||||
|
import type { Plugin } from "vite"; |
||||
|
import { isArray } from "@pureadmin/utils"; |
||||
|
import compressPlugin from "vite-plugin-compression"; |
||||
|
|
||||
|
export const configCompressPlugin = ( |
||||
|
compress: ViteCompression |
||||
|
): Plugin | Plugin[] => { |
||||
|
if (compress === "none") return null; |
||||
|
|
||||
|
const gz = { |
||||
|
// 生成的压缩包后缀
|
||||
|
ext: ".gz", |
||||
|
// 体积大于threshold才会被压缩
|
||||
|
threshold: 0, |
||||
|
// 默认压缩.js|mjs|json|css|html后缀文件,设置成true,压缩全部文件
|
||||
|
filter: () => true, |
||||
|
// 压缩后是否删除原始文件
|
||||
|
deleteOriginFile: false |
||||
|
}; |
||||
|
const br = { |
||||
|
ext: ".br", |
||||
|
algorithm: "brotliCompress", |
||||
|
threshold: 0, |
||||
|
filter: () => true, |
||||
|
deleteOriginFile: false |
||||
|
}; |
||||
|
|
||||
|
const codeList = [ |
||||
|
{ k: "gzip", v: gz }, |
||||
|
{ k: "brotli", v: br }, |
||||
|
{ k: "both", v: [gz, br] } |
||||
|
]; |
||||
|
|
||||
|
const plugins: Plugin[] = []; |
||||
|
|
||||
|
codeList.forEach(item => { |
||||
|
if (compress.includes(item.k)) { |
||||
|
if (compress.includes("clear")) { |
||||
|
if (isArray(item.v)) { |
||||
|
item.v.forEach(vItem => { |
||||
|
plugins.push( |
||||
|
compressPlugin(Object.assign(vItem, { deleteOriginFile: true })) |
||||
|
); |
||||
|
}); |
||||
|
} else { |
||||
|
plugins.push( |
||||
|
compressPlugin(Object.assign(item.v, { deleteOriginFile: true })) |
||||
|
); |
||||
|
} |
||||
|
} else { |
||||
|
if (isArray(item.v)) { |
||||
|
item.v.forEach(vItem => { |
||||
|
plugins.push(compressPlugin(vItem)); |
||||
|
}); |
||||
|
} else { |
||||
|
plugins.push(compressPlugin(item.v)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
return plugins; |
||||
|
}; |
@ -82,6 +82,7 @@ specifiers: |
|||||
unplugin-vue-define-options: 0.7.3 |
unplugin-vue-define-options: 0.7.3 |
||||
vite: ^3.1.8 |
vite: ^3.1.8 |
||||
vite-plugin-cdn-import: ^0.3.5 |
vite-plugin-cdn-import: ^0.3.5 |
||||
|
vite-plugin-compression: ^0.5.1 |
||||
vite-plugin-mock: ^2.9.6 |
vite-plugin-mock: ^2.9.6 |
||||
vite-plugin-remove-console: ^1.1.0 |
vite-plugin-remove-console: ^1.1.0 |
||||
vite-svg-loader: ^3.6.0 |
vite-svg-loader: ^3.6.0 |
||||
@ -184,6 +185,7 @@ devDependencies: |
|||||
unplugin-vue-define-options: 0.7[email protected][email protected] |
unplugin-vue-define-options: 0.7[email protected][email protected] |
||||
vite: 3.1[email protected][email protected] |
vite: 3.1[email protected][email protected] |
||||
vite-plugin-cdn-import: 0.3.5 |
vite-plugin-cdn-import: 0.3.5 |
||||
|
vite-plugin-compression: 0.5[email protected] |
||||
vite-plugin-mock: 2.9[email protected][email protected] |
vite-plugin-mock: 2.9[email protected][email protected] |
||||
vite-plugin-remove-console: 1.1.0 |
vite-plugin-remove-console: 1.1.0 |
||||
vite-svg-loader: 3.6.0 |
vite-svg-loader: 3.6.0 |
||||
@ -7538,6 +7540,22 @@ packages: |
|||||
- rollup |
- rollup |
||||
dev: true |
dev: true |
||||
|
|
||||
|
/vite-plugin-compression/[email protected]: |
||||
|
resolution: |
||||
|
{ |
||||
|
integrity: sha512-5QJKBDc+gNYVqL/skgFAP81Yuzo9R+EAf19d+EtsMF/i8kFUpNi3J/H01QD3Oo8zBQn+NzoCIFkpPLynoOzaJg== |
||||
|
} |
||||
|
peerDependencies: |
||||
|
vite: ">=2.0.0" |
||||
|
dependencies: |
||||
|
chalk: 4.1.2 |
||||
|
debug: 4.3.4 |
||||
|
fs-extra: 10.1.0 |
||||
|
vite: 3.1[email protected][email protected] |
||||
|
transitivePeerDependencies: |
||||
|
- supports-color |
||||
|
dev: true |
||||
|
|
||||
/vite-plugin-mock/[email protected][email protected]: |
/vite-plugin-mock/[email protected][email protected]: |
||||
resolution: |
resolution: |
||||
{ |
{ |
||||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue