hookehuyr

feat: 添加vite-plugin-html插件并配置HTML压缩选项

...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
42 "tailwindcss": "^3.4.1", 42 "tailwindcss": "^3.4.1",
43 "unplugin-auto-import": "^0.17.5", 43 "unplugin-auto-import": "^0.17.5",
44 "unplugin-vue-components": "^0.26.0", 44 "unplugin-vue-components": "^0.26.0",
45 - "vite": "^5.1.0" 45 + "vite": "^5.1.0",
46 + "vite-plugin-html": "^3.2.2"
46 } 47 }
47 } 48 }
......
This diff is collapsed. Click to expand it.
1 /* 1 /*
2 * @Date: 2025-10-30 10:27:43 2 * @Date: 2025-10-30 10:27:43
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-11-03 09:48:52 4 + * @LastEditTime: 2025-11-04 14:37:28
5 * @FilePath: /stdj_h5/vite.config.js 5 * @FilePath: /stdj_h5/vite.config.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -15,6 +15,7 @@ import tailwindcss from 'tailwindcss' ...@@ -15,6 +15,7 @@ import tailwindcss from 'tailwindcss'
15 import autoprefixer from 'autoprefixer' 15 import autoprefixer from 'autoprefixer'
16 import postcsspxtoviewport from 'postcss-px-to-viewport' 16 import postcsspxtoviewport from 'postcss-px-to-viewport'
17 import { createProxy } from './build/proxy' 17 import { createProxy } from './build/proxy'
18 +import { createHtmlPlugin } from 'vite-plugin-html';
18 19
19 export default ({ command, mode }) => { 20 export default ({ command, mode }) => {
20 const root = process.cwd(); 21 const root = process.cwd();
...@@ -36,7 +37,21 @@ export default ({ command, mode }) => { ...@@ -36,7 +37,21 @@ export default ({ command, mode }) => {
36 Components({ 37 Components({
37 resolvers: [VantResolver()], 38 resolvers: [VantResolver()],
38 dts: 'src/components.d.ts' 39 dts: 'src/components.d.ts'
39 - }) 40 + }),
41 + createHtmlPlugin({
42 + // 生产环境下的HTML压缩配置
43 + minify: {
44 + // 核心:删除HTML中的注释
45 + removeComments: true,
46 + // 可选:其他压缩选项(按需开启)
47 + collapseWhitespace: true, // 折叠空白字符
48 + removeRedundantAttributes: true, // 移除冗余属性(如input的type="text")
49 + removeScriptTypeAttributes: true, // 移除script标签的type="text/javascript"
50 + removeStyleLinkTypeAttributes: true, // 移除style/link标签的type="text/css"
51 + minifyCSS: true, // 压缩内嵌CSS
52 + minifyJS: true, // 压缩内嵌JS
53 + },
54 + }),
40 ], 55 ],
41 resolve: { 56 resolve: {
42 alias: { 57 alias: {
......