/** * Vite 打包配置 */ /** * 获取打包基础配置 */ export function getBuildBase(isProd) { return { target: 'es2015', outDir: 'dist', emptyOutDir: true, sourcemap: isProd ? false : 'inline', chunkSizeWarningLimit: 1500, cssCodeSplit: true, cssMinify: isProd, assetsInlineLimit: 4096, reportCompressedSize: false }; } /** * 获取压缩配置 */ export function getTerserOptions(isProd) { if (!isProd) return undefined; return { compress: { drop_console: true, drop_debugger: true, pure_funcs: ['console.log', 'console.info', 'console.debug', 'console.trace'], passes: 2, }, format: { comments: false, } }; } /** * 获取静态资源文件名配置 */ export function getAssetFileNames(assetInfo) { const info = assetInfo.name.split('.'); let extType = info[info.length - 1]; if (/\.(png|jpe?g|gif|svg|webp|ico)$/i.test(assetInfo.name)) { extType = 'img'; } else if (/\.(woff2?|eot|ttf|otf)$/i.test(assetInfo.name)) { extType = 'fonts'; } else if (/\.css$/i.test(assetInfo.name)) { extType = 'css'; } return `${extType}/[name]-[hash].[ext]`; } /** * 获取完整的打包配置 */ export function getBuildConfig(isProd) { const baseConfig = getBuildBase(isProd); return { ...baseConfig, minify: isProd ? 'terser' : false, terserOptions: getTerserOptions(isProd), rollupOptions: { output: { chunkFileNames: 'js/[name]-[hash].js', entryFileNames: 'js/[name]-[hash].js', assetFileNames: getAssetFileNames }, external: isProd ? [] : [], }, optimizeDeps: { include: [ 'vue', 'vue-router', 'pinia', 'dayjs', 'axios', 'js-cookie', 'nprogress' ], exclude: [ '@wangeditor/editor', '@wangeditor/editor-for-vue', '@form-create/antd-designer', '@form-create/ant-design-vue', 'ant-design-vue', '@ant-design/icons-vue' ] } }; }