-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
107 lines (106 loc) · 3.12 KB
/
vite.config.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import {
createStyleImportPlugin,
VxeTableResolve,
} from "vite-plugin-style-import";
import { resolve } from "path";
import MonacoEditorNlsPlugin, {
esbuildPluginMonacoEditorNls,
Languages,
} from "./plugin";
const zh_CN = require("./plugin/main.i18n.json");
import Pages from "vite-plugin-pages";
import AutoImport from "unplugin-auto-import/vite";
import { createHtmlPlugin } from "vite-plugin-html";
export default ({ mode }) => {
return defineConfig({
base: "/monaco-editor-echarts/",
build: {
outDir: "docs",
},
resolve: {
alias: {
"@": resolve("./src"),
},
},
optimizeDeps: {
/** vite 版本需要大于等于2.3.0 */
esbuildOptions: {
plugins: [
esbuildPluginMonacoEditorNls({
locale: Languages.zh_hans,
localeData: zh_CN.contents,
}),
],
},
},
plugins: [
vue(),
createHtmlPlugin({
minify: false,
// 入口,不需要在`index.html`内添加 script 标签,原有标签需要删除
entry: "src/main.ts",
// 将 `index.html`存放在指定文件夹
template: "index.html",
// 需要注入 index.html ejs 模版的数据
inject: {
data: {
title: "echarts示例",
injectScript:
mode === "development"
? `<script src="./dev.js"></script>`
: `<script src="./config.js"></script>`,
},
},
}),
// 自动导入api
AutoImport({
imports: ["vue", "vue-router"],
dirs: ["src/store"],
dts: "src/auto-import.d.ts",
}),
Pages({
// 自动读取src/views下的vue文件,生成路由信息,默认路由路径'/‘
dirs: [{ dir: "src/views", baseRoute: "/" }],
// 异步方式加载路由组件
importMode: "async",
// 遍历路由信息,给默认路由加一个redirect
// extendRoute(route) {
// if (route.path === "/") return { ...route, redirect: "login" }
// }
}),
// 汉化
MonacoEditorNlsPlugin({
locale: Languages.zh_hans,
localeData: zh_CN.contents,
}),
Components({
dirs: ["src/components"], // 要导入组件的目录路径
deep: true, // 搜索子目录
dts: "src/components.d.ts", // 生成 `components.d.ts` 全局声明
// 配置vxe-table的自动注册组件
resolvers: [
// ElementPlusResolver(),
(componentName) => {
if (componentName.startsWith("Vxe"))
return { name: componentName.slice(3), from: "vxe-table" };
},
],
}),
// 配置vxe-table的自动导入组件样式
createStyleImportPlugin({
resolves: [VxeTableResolve()],
}),
],
server: {
// 设置代理
proxy: {
"/login": "https://github.com",
},
port: 9005, // 端口号
open: true, // 是否自动打开浏览器
},
});
};