vite.config.ts的完整配置已经上传到github,点击查看这是通过这个配置打包出来的项目地址:Demo地址启用JSX编写高性能组件,JSX列组件newVue({el:'#demo',render:function(h){return(Helloworld!)}})从'@vitejs/plugin-vue-jsx导入vueJsx'export{vueJsx}Configuremulti-pagerollupOptions:{input:{example:path.resolve(process.cwd(),'index.html'),//把页面放到外面,路径短防止src/packages/web/index.html,建议vite将key(web,lib)映射到一个页面路径,避免出现这个问题lib:path.resolve(process.cwd(),'lib.html')},}compress最小输出rollupOptions:{//两种方式//一种,也可以指定包名来打包//output:{//manualChunks:{//"vxe-table":["vxe-table"],//"echarts":["echarts"],//"xe-utils":["xe-utils"],//"lodash":['lodash'],//"ant-design-vue":['ant-design-vue'],//"@antv/g2plot":['@antv/g2plot'],//"@antv/g2":['@antv/g2'],//}//},//二、自动拆分包名输出chunkSizeWarningLimit配置大小output:{chunkFileNames:'assets/js/[name]-[hash].js',entryFileNames:'assets/js/[name]-[hash].js',assetFileNames:'assets/static/[name]-[hash].[ext]',manualChunks(id:任何){if(id.includes('node_modules')){returnid.toString().split('node_modules/')[1].split('/')[0].toString();}}},},去掉consoleterserOptions:{compress:{drop_console:true,drop_debugger:true,},}配置aliasresolve:{alias:{//如果报错找不到__dirname,需要安装node,执行yarn添加@types/node--save-dev"@":path.resolve(__dirname,"src"),"__ROOT__":path.resolve(__dirname,""),"comps":path.resolve(__dirname,"src/components"),}},配置别名的时候,为了让编辑器更好的识别别名,需要配置jsconfig.json文件,和vite.config.ts放在同一层级,并且编辑器会自动读取{"compilerOptions":{"baseUrl":"./","paths":{"@/*":["src/*"],"__ROOT__/*":["*"]}},"exclude":["node_modules"]}vxe-table形式,按需加载一个基于Vue的PC端表格组件,支持增删改查,虚拟列表,虚拟树,懒加载,快捷菜单,数据校验,打印导出,表单渲染,数据分页,弹窗,自定义模板,renderer,Thieves灵活配置项,扩展接口等importstyleImportfrom'vite-plugin-style-import'//按需加载模块exportfunctionconfigStyleImport(){returnstyleImport({libs:[{libraryName:'vxe-table',esModule:true,resolveComponent:(name)=>`vxe-table/es/${name}`,resolveStyle:(name)=>`vxe-table/es/${name}/style.css`}]})}启用压缩importviteCompressionfrom'vite-plugin-compression'//启用压缩导出函数configViteCompression(){//启用压缩[文档](https://github.com/anncwb/vite-plugin-compression/blob/main/README.zh_CN.md)返回viteCompressi上({详细:真,禁用:假,//filter:()=>{},//那些资源不压缩threshold:1024*50,//体积大于阈值会压缩,unitbdeleteOriginFile:false,//是否删除源fileaftercompressionalgorithm:'gzip',//压缩算法,可选['gzip','brotliCompress','deflate','deflateRaw']ext:'.gz',//生成的压缩包后缀})}只需要配置CDNword即自动生成模板引用的cdn路径元素加',var:'ElementPlus',路径:'https://unpkg.com/element-plus/lib/index.full.js',css:'https://unpkg.com/element-plus/lib/theme-chalk/index.css',},{name:'vant',var:'vant',path:'https://cdn.jsdelivr.net/npm/vant@next/lib/vant.min.js',css:'https://cdn.jsdelivr.net/npm/vant@next/lib/index.css',}]})}将变量注入html模板importhtml来自'vite-plugin-html'exportfunctionconfigHtml(opt:any){returnhtml({inject:{injectData:{...opt.variables}},minify:true})}配置构建依赖包liblib:{entry:path.resolve(process.cwd(),'src/packages/install.ts'),name:'vueViteAdminTs',//构建依赖包时,对外暴露的名称fileName:(format:string)=>`index.${format}.js`,rollupOptions:{external:['vue','vue-router'],output:{globals:{vue:'Vue'}}}},rollupOptions:{output:{inlineDynamicImports:true,}}配置代理导出函数configServer(){return{host:'0.0.0.0',port:8290,https:false,proxy:{'^/api':{target:'http://127.0.0.1:7001',changeOrigin:true,rewrite:(path:any)=>path.replace(/^/api/,'')}}}}配置less修改全局less变量importthemefrom'../../src/包/theme/ming'exportfunctionconfigCss(){return{preprocessorOptions:{less:{modifyVars:{...theme},javascriptEnabled:true,},}}}推荐配置windicssimportWindiCSSfrom'vite-plugin-windicss'exportdefault{plugins:[WindiCSS(),],}如果担心命名冲突,在根目录下新建windi.config.ts,可以通过以下方式给属性模式添加自定义前缀:exportdefault{attributify:{prefix:'w:',},}使用以下示例:按钮vite-svg-loadervite-svg-loader插件允许你像引用组件一样引用svg文件vite-plugin-componentsvite-plugin-components可以实现组件库或内部组件的自动按需导入,无需手动导入,可以帮助我们节省大量导入代码importVuefrom'@vitejs/plugin-vue'importViteComponentsfrom'vite-plugin-components'exportdefault{plugins:[Vue(),ViteComponents()],};嗯,关于vite的配置我先写到这里,至于后面有新的配置或者新的变化,我会在这个仓库里配置,验证可行性