-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
118 lines (111 loc) · 3.63 KB
/
vite.config.ts
File metadata and controls
118 lines (111 loc) · 3.63 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { globSync } from "node:fs";
import { env, cwd } from "node:process";
import { extname, relative, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig, loadEnv } from "vite";
import dts from "vite-plugin-dts";
import eslint from "vite-plugin-eslint";
import browserslist from "browserslist";
import { browserslistToTargets } from "lightningcss";
import UnoCSS from "unocss/vite";
const version = env.npm_package_version;
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, cwd(), "");
return {
resolve: {
alias: {
"@root": resolve(__dirname, "./"),
"@modules": resolve(__dirname, "./node_modules"),
"@": resolve(__dirname, "./src"),
},
},
base: env.BASE_PATH,
test: {
// Lit recommends using browser environment for testing
// https://lit.dev/docs/tools/testing/#testing-in-the-browser
browser: {
enabled: true,
provider: "playwright",
instances: [{ browser: "chromium" }],
},
},
css: {
transformer: "lightningcss",
lightningcss: {
targets: browserslistToTargets(browserslist(">= 0.25%")),
},
},
build: {
cssCodeSplit: true,
cssMinify: "lightningcss",
lib: {
entry: {
main: resolve(__dirname, "./src/main.ts"),
},
formats: ["es"],
name: "my-ui",
fileName: (format) => `index.${format}.js`,
},
rollupOptions: {
// If we want to publish standalone components we don't externalize lit,
// if you are going to use lit in your own project, you can make it a dep instead.
// @ref: https://leonradley.com/articles/web-components/2022-02-vite-lit-storybook
external: [/^lit/, /^virtual:uno.css/],
input: Object.fromEntries(
globSync(
["src/elements/**/*.ts", "src/main.ts", "src/styles/*.css"],
{
exclude: (fileName) => {
return (
fileName.includes("stories") || fileName.includes("test")
);
},
}
).map((file) => {
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
const entryName = relative(
"src",
file.slice(0, file.length - extname(file).length)
);
/** expanded relative paths to absolute paths */
const entryUrl = fileURLToPath(new URL(file, import.meta.url));
return [entryName, entryUrl];
})
),
output: {
banner: `/*! my UI v${version} */`,
format: "commonjs",
entryFileNames: "[name].js",
assetFileNames: ({ originalFileNames }) => {
console.log(originalFileNames);
const filePath = originalFileNames[0];
/** put component css next to its js */
if (filePath?.includes("/elements/")) {
return "elements/[name]/[name][extname]";
}
/** move all other styles here */
if (filePath?.includes("/styles/")) {
return "[name][extname]";
}
/** move all other assets to the default location */
return "assets/[name][extname]";
},
},
},
sourcemap: true,
emptyOutDir: true,
},
plugins: [
eslint(),
UnoCSS({
mode: "shadow-dom",
}),
dts({
rollupTypes: true,
tsconfigPath: "./tsconfig.json",
exclude: ["**/*.stories.ts", "src/test", "**/*.test.ts"],
}),
],
};
});