Vue3中(vite.config.js)配置打包的时候去除console.log
参考:https://www.cnblogs.com/lovewhatIlove/p/16476165.html
安装terser
npm add -D terser
vite中配置
import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import vueJsx from "@vitejs/plugin-vue-jsx"; import visualizer from "rollup-plugin-visualizer"; import viteCompression from "vite-plugin-compression"; import { viteZip } from "vite-plugin-zip-file"; import mpaPlugin from "vite-plugin-mpa-plus"; const getBuildInfo = require("./version/version.js"); const path = require("path"); export default defineConfig({ base: "/", // 开发或生产环境服务的公共基础路径 plugins: [ vue(), mpaPlugin({ pages: { index: { filename: "index.html", template: "public/index.html", inject: { data: { title: "mpa-app1" } } }, version: { filename: "version.html", template: "version/index.html", inject: { data: { buildInfo: getBuildInfo() } } } } }), viteZip({ folderPath: path.resolve(__dirname, "dist"), outPath: path.resolve(__dirname), zipName: "dist.zip" }), vueJsx(), visualizer({ open: false, gzipSize: true }), viteCompression({ deleteOriginFile: false, algorithm: "gzip" }) ], resolve: { // 定义路径别名 alias: { "@": path.resolve(__dirname, "src") }, // 导入时省略扩展名 extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"] }, server: { host: "0.0.0.0", port: 9999, open: true, proxy: { "/yyfnzx": { target: "http://xx.xx.xx.xx:18895/yyfnzx", changeOrigin: true, rewrite: path => path.replace(/^\/yyfnzx/, "") }, "/empower": { target: "http://192.168.1.141:8180/empower", changeOrigin: true, rewrite: path => path.replace(/^\/empower/, "") } // 'empower/ucs': { // // target: '********************', // target: '*********************', // changeOrigin: true // }, } }, build: { outDir: "./dist/", brotliSize: false, // 关闭打包过程中计算包的大小 cssCodeSplit: true, //启用/禁用 CSS 代码拆分 assetsInlineLimit: 4096, // 图片转base64编码的阈值 sourcemap: false, //构建后是否生成 source map 文件 rollupOptions: { output: { manualChunks(id) { if (id.includes("node_modules")) { return id .toString() .split("node_modules/")[1] .split("/")[0] .toString(); } }, chunkFileNames: "static/js/[name]-[hash].js", entryFileNames: "static/js/[name]-[hash].js", assetFileNames: "static/[ext]/[name]-[hash].[ext]" } }, // start = 核心配置 minify: 'terser', terserOptions: { compress: { drop_console: true, drop_debugger: true } } // end = 核心配置 } }); // https://vitejs.dev/config/
学而不思则罔,思而不学则殆!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具