-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.lib.ts
More file actions
100 lines (96 loc) · 2.83 KB
/
vite.config.lib.ts
File metadata and controls
100 lines (96 loc) · 2.83 KB
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
import VueI18n from "@intlify/unplugin-vue-i18n/vite"
import vue from "@vitejs/plugin-vue"
import { glob } from "glob"
import path from "path"
import url from "url"
import { defineConfig } from "vite"
import { viteStaticCopy } from "vite-plugin-static-copy"
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
// Read peer dependencies from package.json to use as externals.
const packageJson = await import("./package.json", { with: { type: "json" } })
const peerDependencies = Object.keys(packageJson.default.peerDependencies || {})
const entries = await Promise.all([glob("src/**/*.vue", { cwd: __dirname }), glob("src/**/*.ts", { cwd: __dirname })]).then(([vueFiles, tsFiles]) =>
[...vueFiles, ...tsFiles]
.filter((file) => !file.includes(".test.") && !file.endsWith(".d.ts") && !file.endsWith(".css") && file !== "src/test-setup.ts" && !file.startsWith("src/__mocks__"))
.reduce(
(acc, file) => {
// Strip .ts and .vue extensions from the filename.
const name = file.replace(/^src\//, "").replace(/\.(vue|ts)$/, "")
acc[name] = path.resolve(__dirname, file)
return acc
},
{} as Record<string, string>,
),
)
export default defineConfig({
define: {
__VUE_OPTIONS_API__: false,
},
plugins: [
vue(),
VueI18n({
include: [path.resolve(__dirname, "src/locales/**")],
runtimeOnly: true,
compositionOnly: true,
dropMessageCompiler: true,
fullInstall: true,
forceStringify: true,
}),
viteStaticCopy({
targets: [
{
src: "src/theme.css",
dest: ".",
rename: { stripBase: 1 },
},
{
src: "src/**/*.d.ts",
dest: ".",
rename: { stripBase: 1 },
},
],
}),
],
resolve: {
alias: {
"@": "/src",
},
},
build: {
lib: {
entry: entries,
formats: ["es"],
},
// The library does not need LICENSE.txt and robots.txt bundled.
copyPublicDir: false,
rollupOptions: {
onwarn(warning, warn) {
// Suppress "empty chunk" warning for intentionally empty index file.
if (warning.code === "EMPTY_BUNDLE" && warning.message.includes("index")) {
return
}
warn(warning)
},
external: (id) => {
// Externalize CSS files - consumers have to use their own TailwindCSS setup.
if (id.endsWith(".css")) {
return true
}
// Externalize all peer dependencies.
return peerDependencies.some((peer) => id === peer || id.startsWith(peer + "/"))
},
output: {
preserveModules: true,
preserveModulesRoot: "src",
},
preserveEntrySignatures: "strict",
},
outDir: "lib",
emptyOutDir: true,
sourcemap: true,
target: ["esnext"],
},
esbuild: {
legalComments: "none",
},
})