-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
64 lines (61 loc) · 1.77 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
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Markdown from "./src/plugins/index";
const vueJsx = require("@vitejs/plugin-vue-jsx");
const eslint = require("@rollup/plugin-eslint");
const path = require("path");
// https://vitejs.dev/config/
export default defineConfig(() => {
const isLibraryMode = process.env.target === "library";
const config = {
optimizeDeps: {
include: ["theme"] //! vite bug:由于tailwindcss 走的node 所以这个文件需要 commoonjs,但是浏览器中只能使用es module,所以需要vite构建。
},
server: {
// force: true
},
plugins: [
vue({
include: [/\.vue$/, /\.md$/, /mk.*/]
}),
Markdown({
headEnabled: true
}),
vueJsx({}),
eslint({
include: ["src/**/*.js", "src/**/*.ts"],
exclude: ["**/node_modules", "**/*.scss", "**/*.css", "**/*.png", "**/*.svg", "**/*.jpg"]
})
],
resolve: {
alias: {
// 解决方案,vite 虚拟文件不能解析相对路径
"@components": "/src/components"
},
preserveSymlinks: isLibraryMode
}
};
console.log(process.env.target, "library");
if (isLibraryMode) {
const libaryConfig = {
build: {
lib: { entry: "./src/index.ts", name: "memo", formats: ["es", "umd"] },
rollupOptions: {
// 请确保外部化那些你的库中不需要的依赖
external: ["vue"],
output: {
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
vue: "Vue"
}
}
},
minify: true
},
publicDir: ""
};
Object.assign(config, libaryConfig);
console.log(config);
}
return config;
});