-
Notifications
You must be signed in to change notification settings - Fork 9
/
vite.config.ts
131 lines (125 loc) · 4.88 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { extname, relative, resolve } from "path";
import { fileURLToPath } from "node:url";
import { glob } from "glob";
import { libInjectCss } from "vite-plugin-lib-inject-css";
import dts from "vite-plugin-dts";
import sass from "sass";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const config_resolve = {
alias: {
"@quill": resolve(__dirname, "lib/styles/quill"),
"@quill-custom": resolve(__dirname, "lib/styles/custom"),
"@components": resolve(__dirname, "lib/components"),
"@hooks": resolve(__dirname, "lib/hooks"),
"@providers": resolve(__dirname, "lib/providers"),
"@utils": resolve(__dirname, "lib/utils"),
"@styles": resolve(__dirname, "lib/styles"),
"@types": resolve(__dirname, "lib/types.ts"),
},
};
const dts_plugin = dts({
include: ["lib"],
exclude: [
"**/mocks/**",
"lib/**/*.spec.tsx",
"lib/**/*.test.tsx",
"lib/**/*.stories.tsx",
],
});
const css_preprocessor = {
preprocessorOptions: {
scss: {
implementation: sass,
},
},
};
const config =
mode === "es"
? {
plugins: [
react(),
libInjectCss(),
dts_plugin
],
css: css_preprocessor,
resolve: config_resolve,
build: {
outDir: "dist-es",
lib: {
entry: resolve(__dirname, "lib/main.ts"),
formats: ["es"],
},
copyPublicDir: false,
cssCodeSplit: false,
rollupOptions: {
external: ["react", "react-dom"],
input: Object.fromEntries(
glob
.sync("lib/**/*.{ts,tsx}", {
ignore: [
"**/mocks/**",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/__tests__/**",
"**/*.stories.tsx",
"**/*.stories.ts",
],
})
.map((file) => {
return [
// The name of the entry point
// lib/nested/foo.ts becomes nested/foo
relative(
"lib",
file.slice(
0,
file.length -
extname(file).length,
),
),
// The absolute path to the entry file
// lib/nested/foo.ts becomes /project/lib/nested/foo.ts
fileURLToPath(
new URL(file, import.meta.url),
),
];
}),
),
output: {
assetFileNames: "assets/[name][extname]",
entryFileNames: "[name].js",
},
},
},
}
: {
plugins: [
react(),
dts_plugin
],
resolve: config_resolve,
build: {
outDir: "dist-cjs",
lib: {
entry: resolve(__dirname, "lib/main.ts"),
formats: ["cjs"],
},
copyPublicDir: false,
cssCodeSplit: false,
rollupOptions: {
external: ["react", "react-dom"],
output: {
entryFileNames: "[name].cjs",
chunkFileNames: "chunks/[name].cjs",
assetFileNames: "assets/[name][extname]",
},
},
},
};
return config;
});