1 Star 0 Fork 19

huangzi/vue-next-uniapp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.ts 2.71 KB
一键复制 编辑 原始数据 按行查看 历史
三线程序猿 提交于 2022-06-28 09:07 . feat:init框架
/*
* @Description:
* @Author: shuliang
* @Date: 2022-06-21 15:58:08
* @LastEditTime: 2022-06-28 08:39:17
* @LastEditors: shuliang
*/
import { ConfigEnv, defineConfig, loadEnv } from 'vite'
import { resolve } from 'path'
import { viteMockServe } from 'vite-plugin-mock'
import uni from '@dcloudio/vite-plugin-uni'
const pathResolve = (dir: string): any => {
return resolve(__dirname, '.', dir)
}
const alias: Record<string, string> = {
'@': pathResolve('./src/'),
}
const viteConfig = defineConfig((mode: ConfigEnv) => {
const env = loadEnv(mode.mode, process.cwd())
const localEnabled: boolean = (env.VITE_USE_MOCK as unknown as boolean) || false
const prodEnabled: boolean = (env.USE_CHUNK_MOCK as unknown as boolean) || false
return {
plugins: [
uni(),
viteMockServe({
// ↓解析根目录下的mock文件夹
mockPath: 'mock',
localEnabled: localEnabled, // 开发打包开关
prodEnabled: prodEnabled, // 生产打包开关
supportTs: true, // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件。
watchFiles: true, // 监视文件更改
}),
],
root: process.cwd(),
resolve: { alias },
base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
server: {
host: '0.0.0.0',
port: env.VITE_PORT as unknown as number,
open: env.VITE_OPEN,
proxy: {
[env.VITE_BASE]: {
target: 'https://gitee.com',
ws: true,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(env.VITE_BASE, 'g'), '/'),
},
},
},
build: {
outDir: 'dist',
minify: 'terser',
sourcemap: false,
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
entryFileNames: `assets/[name].${new Date().getTime()}.js`,
chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
compact: true,
manualChunks: {
vue: ['vue', 'vue-router', 'vuex'],
echarts: ['echarts'],
},
},
},
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
ie8: true,
output: {
comments: true,
},
},
},
css: {
postcss: {
plugins: [
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: (atRule) => {
if (atRule.name === 'charset') {
atRule.remove()
}
},
},
},
],
},
},
}
})
export default viteConfig
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huangzi-mvp/vue-next-uniapp.git
git@gitee.com:huangzi-mvp/vue-next-uniapp.git
huangzi-mvp
vue-next-uniapp
vue-next-uniapp
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385