-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
70 lines (67 loc) · 1.62 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
import fs from "node:fs"
import path, { resolve } from "node:path"
import react from "@vitejs/plugin-react"
import { type Plugin, mergeConfig } from "vite"
import dts from "vite-plugin-dts"
import baseConfig from "./vite.preview.config"
/**
* Patch generated entries and import their corresponding CSS files.
*/
const patchCssFiles: Plugin = {
name: "patch-css",
apply: "build",
writeBundle() {
// inject css imports to the files
const outDir = path.resolve("build")
;["repl-react", "codemirror-editor"].forEach((file) => {
const filePath = path.resolve(outDir, `${file}.js`)
const content = fs.readFileSync(filePath, "utf-8")
fs.writeFileSync(filePath, `import './${file}.css'\n${content}`)
})
},
}
// https://vite.dev/config/
export default mergeConfig(baseConfig, {
plugins: [
react(),
dts({
rollupTypes: true,
insertTypesEntry: true,
entryRoot: "src",
exclude: ["**/*.test.ts", "**/*.test.tsx"],
}),
patchCssFiles,
],
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
optimizeDeps: {
exclude: ["typescript"],
},
server: {
headers: {
"*.wasm": ["application/wasm"],
},
},
build: {
outDir: "build",
target: "esnext",
minify: false,
lib: {
entry: {
"repl-react": "./src/index.ts",
"codemirror-editor": "./src/components/Editor/CodeMirror/index.tsx",
},
formats: ["es"],
fileName: () => "[name].js",
},
rollupOptions: {
external: ["react", "react-dom"],
output: {
chunkFileNames: "chunks/[name]-[hash].js",
},
},
},
})