-
Notifications
You must be signed in to change notification settings - Fork 54
/
vite.config.ts
129 lines (123 loc) · 3.57 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
import { defineConfig } from "vite";
import { resolve } from "path";
import pkg from "./package.json";
import { replaceCodePlugin } from "vite-plugin-replace";
// Configuration commune
const commonConfig = {
sourcemap: true,
};
const commonPlugins = [
replaceCodePlugin({
replacements: [
{
from: /__SCD_BUILD_DATE__/g,
to: new Date().toISOString().split("T")[0],
},
{
from: /__SCD_VERSION__/g,
to: pkg.version,
},
],
}),
];
// Configuration pour le build ES
const esConfig = defineConfig({
build: {
outDir: "dist",
emptyOutDir: true,
minify: true,
...commonConfig,
lib: {
entry: resolve(__dirname, "src/core/simplyCountdown.ts"),
formats: ["es"],
fileName: () => "simplyCountdown.js",
},
rollupOptions: {
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name === "style.css") {
return "themes/[name][extname]";
}
return "[name][extname]";
},
},
},
},
plugins: commonPlugins,
});
// Configuration pour le build UMD
const umdConfig = defineConfig({
build: {
outDir: "dist",
emptyOutDir: false,
minify: "terser",
terserOptions: {
compress: {
drop_console: true,
},
},
...commonConfig,
lib: {
entry: resolve(__dirname, "src/core/simplyCountdown.umd.ts"),
name: "simplyCountdown",
formats: ["umd"],
fileName: () => "simplyCountdown.umd.js",
},
rollupOptions: {
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name === "style.css") {
return "themes/[name][extname]";
}
return "[name][extname]";
},
format: "umd",
name: "simplyCountdown",
amd: {
id: "simplyCountdown",
},
},
},
},
plugins: commonPlugins,
});
// Configuration pour la documentation
const docsConfig = defineConfig({
root: "docs/src",
base: "./",
publicDir: resolve(__dirname, "docs/src/public"),
build: {
outDir: "../dist",
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
input: {
main: resolve(__dirname, "docs/src/index.html"),
},
output: {
entryFileNames: "assets/[name].min.js",
chunkFileNames: "assets/[name].min.js",
assetFileNames: (assetInfo) => {
// here deprecated stuff, should improve later, maybe I misunderstood something
if (assetInfo.originalFileName?.includes("public/favicon")) {
return "favicon/[name][extname]";
} else if (assetInfo.name?.includes(".css")) {
return "assets/[name].min.[extname]";
}
return "ssssss/[name][extname]";
},
},
},
},
plugins: commonPlugins,
});
// Export la configuration en fonction du mode
export default ({ mode }: { mode?: string }) => {
if (mode === "docs") {
return docsConfig;
}
if (mode === "umd") {
return umdConfig;
}
return esConfig;
};