代码拉取完成,页面将自动刷新
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
// import viteCompression from 'vite-plugin-compression'
import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
import htmlMinimize from '@sergeymakinen/vite-plugin-html-minimize'
// https://vitejs.dev/config/
export default defineConfig({
server: {
// 监听所有地址(包括局域网与公网),方便内网调试
host: '0.0.0.0',
proxy: {
'^/api(-login)?/': 'http://0.0.0.0',
'^/login/$': 'http://0.0.0.0',
},
},
base: './',
plugins: [
mockDevServerPlugin(),
// viteCompression({
// algorithm: 'gzip',
// threshold: 256, // >=256字节时压缩
// verbose: true, // 打印压缩结果
// deleteOriginFile: false, // 不删除源文件
// filter: /\.(js|json|css)$/i // 文件名匹配
// }),
htmlMinimize({
minifierOptions: {
collapseWhitespace: true,
html5: true,
keepClosingSlash: false,
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
}
}),
{
// script执行前阻止网页渲染
// https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/script
name: "scriptBlockingRender",
transformIndexHtml(html) {
return html.replaceAll(
'<script type="module"',
'<script type="module" blocking="render" async'
);
}
},
{
name: "removeI18nElement",
transformIndexHtml(html) {
return html.replaceAll(
'I18nElement',
''
);
}
},
// {
// // 添加版本号
// name: "WriteVersion",
// apply: 'build',
// closeBundle() {
// if (process.env.npm_package_version) {
// fs.writeFileSync("./dist/version.txt", process.env.npm_package_version)
// console.log("WriteVersion Done");
// }
// },
// },
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
build: {
target: 'es2022',
minify: 'terser',
reportCompressedSize: true, // 是否使用vite自带的方式打印压缩后的大小
rollupOptions: {
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`,
}
},
modulePreload: {
polyfill: false,
},
chunkSizeWarningLimit: Infinity,
cssCodeSplit: false,
assetsInlineLimit: 0,
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。