feat: 使用terser来控制清除

This commit is contained in:
Burt 2023-12-23 12:04:31 +08:00
parent 9390af654b
commit 16fcb3f4eb
4 changed files with 30 additions and 4 deletions

View File

@ -118,6 +118,7 @@
"stylelint-config-recommended-vue": "^1.5.0",
"stylelint-config-standard": "^35.0.0",
"stylelint-config-standard-scss": "^12.0.0",
"terser": "^5.26.0",
"typescript": "^4.9.4",
"unocss": "^0.58.0",
"unplugin-auto-import": "^0.17.2",

3
pnpm-lock.yaml generated
View File

@ -175,6 +175,9 @@ devDependencies:
stylelint-config-standard-scss:
specifier: ^12.0.0
version: 12.0.0(postcss@8.4.32)(stylelint@16.0.2)
terser:
specifier: ^5.26.0
version: 5.26.0
typescript:
specifier: ^4.9.4
version: 4.9.5

11
src/env.d.ts vendored
View File

@ -1,4 +1,5 @@
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />
declare module '*.vue' {
import { DefineComponent } from 'vue'
@ -6,3 +7,13 @@ declare module '*.vue' {
const component: DefineComponent<{}, {}, any>
export default component
}
interface ImportMetaEnv {
readonly VITE_APP_TITLE: string
readonly VITE_SERVER_PORT: string
// 更多环境变量...
}
interface ImportMeta {
readonly env: ImportMetaEnv
}

View File

@ -22,11 +22,13 @@ import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import UnoCSS from 'unocss/vite'
import autoprefixer from 'autoprefixer'
const htmlPlugin = () => {
const htmlPlugin = (title: string) => {
return {
name: 'html-transform',
transformIndexHtml(html) {
return html.replace('%BUILD_DATE%', dayjs().format('YYYY-MM-DD HH:mm:ss'))
return html
.replace(/<title>(.*?)<\/title>/, `<title>${title}</title>`)
.replace('%BUILD_DATE%', dayjs().format('YYYY-MM-DD HH:mm:ss'))
},
}
}
@ -46,7 +48,7 @@ export default ({ mode }) => {
UniLayouts(),
Uni(),
UnoCSS(),
htmlPlugin(),
htmlPlugin(env.VITE_APP_TITLE),
svgLoader(),
// 打包分析插件
visualizer(),
@ -134,7 +136,7 @@ export default ({ mode }) => {
server: {
host: '0.0.0.0',
hmr: true,
port: 7001,
port: Number.parseInt(env.VITE_APP_PORT, 10),
// 自定义代理规则
proxy: {
// 选项写法
@ -145,5 +147,14 @@ export default ({ mode }) => {
},
},
},
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: env.VITE_DELETE_CONSOLE === 'true',
drop_debugger: env.VITE_DELETE_CONSOLE === 'true',
},
},
},
})
}