-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
45 lines (42 loc) · 1.1 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
const __COMPONENT_NAME__ = "My Component";
export default defineConfig(({ mode }) => ({
plugins: [
react({
jsxRuntime: "classic",
}),
cssInjectedByJsPlugin({
preRenderCSSCode: (cssCode) =>
cssCode.replace(
/__COMPONENT_NAME__/g,
__COMPONENT_NAME__.replace(/-/g, "_").replace(/\s/g, "_")
),
}),
],
resolve:
mode === "development"
? {}
: {
alias: {
react: "https://unpkg.com/[email protected]/umd/react.development.js",
"react-dom":
"https://unpkg.com/[email protected]/umd/react-dom.development.js",
},
},
build: {
lib: {
entry: "src/lib.tsx",
name: "wmc",
fileName: (format) => `cc.${format}.js`,
formats: ["iife"],
},
},
define: {
__COMPONENT_NAME__: JSON.stringify(
__COMPONENT_NAME__.replace(/-/g, "_").replace(/\s/g, "_")
),
"process.env.NODE_ENV": '"production"',
},
}));