1 Star 3 Fork 1

三线程序猿/vue-robust-admin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vite.config.ts 3.19 KB
一键复制 编辑 原始数据 按行查看 历史
三线程序猿 提交于 2022-11-17 11:12 . feat:新增unocss功能
/*
* @Description:
* @Author: shuliang
* @Date: 2022-05-04 11:46:05
* @LastEditTime: 2022-08-25 08:32:04
* @LastEditors: shuliang
*/
import vue from '@vitejs/plugin-vue';
import { viteMockServe } from 'vite-plugin-mock';
import AutoImport from 'unplugin-auto-import/vite';
import { resolve } from 'path';
import { defineConfig, loadEnv, ConfigEnv } from 'vite';
// 引入Unocss
import Unocss from 'unocss/vite';
import { presetUno, presetAttributify, presetIcons } from 'unocss';
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: [
vue(),
Unocss({
// 使用Unocss
presets: [presetUno(), presetAttributify(), presetIcons()],
}),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
],
imports: ['vue', 'vue-router'], // 自动导入vue和vue-router相关函数
eslintrc: {
enabled: false, // 若没此json文件,先开启,生成后在关闭
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true,
},
dts: 'src/auto-import.d.ts', // 生成 `auto-import.d.ts` 全局声明
}),
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/sl19940902/vue-robust-admin.git
git@gitee.com:sl19940902/vue-robust-admin.git
sl19940902
vue-robust-admin
vue-robust-admin
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385