uniapp Vue2升级Vue3使用Vite分包
uniapp Vue2使用webpack打包配置
根目录下创建vue.config.js文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | const path = require( 'path' ) const CopyWebpackPlugin = require( 'copy-webpack-plugin' ) //最新版本copy-webpack-plugin插件暂不兼容,推荐v5.0.0 let filePath = '' let Timestamp = '' //编译环境判断,判断是否H5环境 if (process.env.UNI_PLATFORM === 'h5' ) { filePath = 'static/js/' ; //打包文件存放文件夹路径 Timestamp = '.' + new Date().getTime(); //时间戳 } module.exports = { configureWebpack: { output: { // 输出重构 打包编译后的 文件目录 文件名称 【模块名称.时间戳】 filename: `${filePath}[name]${Timestamp}.js`, chunkFilename: `${filePath}[name]${Timestamp}.js` }, plugins: [ // 自定义分包静态资源目录 new CopyWebpackPlugin([{ from: path.join(__dirname, '/static_sub' ), to: path.join(__dirname + '/unpackage/' , 'dist' , process.env.NODE_ENV === 'production' ? 'build' : 'dev' , process.env.UNI_PLATFORM, '/' ) } ]) ] }, chainWebpack: (config) => { // 发行或运行时启用了压缩时会生效 config.optimization.minimizer( 'terser' ).tap((args) => { const compress = args[0].terserOptions.compress // 非 App 平台移除 console 代码(包含所有 console 方法,如 log,debug,info...) compress.drop_console = true compress.pure_funcs = [ '__f__' , // App 平台 vue 移除日志代码 // 'console.debug' // 可移除指定的 console 方法 ] return args }) } } |
uniapp Vue3使用Vite打包配置
根目录下创建vite.config.js文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import path from 'path' import fs from 'fs-extra' import { defineConfig } from 'vite' import uni from '@dcloudio/vite-plugin-uni' function copyFile() { return { enforce: 'post' , async writeBundle() { await fs.copy( path.join(__dirname, '/static_sub' ), path.join(__dirname + '/unpackage/' , 'dist' , process.env.NODE_ENV === 'production' ? 'build' : 'dev' , process.env.UNI_PLATFORM, '/' ) ) }, } } let filePath = '' let Timestamp = '' //编译环境判断,判断是否H5环境 if (process.env.UNI_PLATFORM === 'h5' ) { filePath = 'assets/' ; //打包文件存放文件夹路径 Timestamp = '.' + new Date().getTime(); //时间戳 } export default defineConfig({ plugins: [ uni(), copyFile() ], build: { terserOptions: { compress: { // 发布时删除 console drop_console: true , }, }, rollupOptions: { output:{ // 输出重构 打包编译后的 文件目录 文件名称 【模块名称.时间戳】 // 入口文件名 entryFileNames: `${filePath}[name]${Timestamp}.js`, // 块文件名 chunkFilename: `${filePath}[name]${Timestamp}.js`, // 资源文件名 css 图片等等 assetFileNames: `${filePath}[name]${Timestamp}.[ext]` } } } }) |
分类:
uniapp
, uniapp框架搭建
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义