-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
vite.config.ts
84 lines (81 loc) · 2.7 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
import * as path from 'node:path'
import fs from 'node:fs'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
import tailwind from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import postcssReplace from 'postcss-replace'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const isDev = mode !== 'production'
return {
plugins: [
react(),
dts({
rollupTypes: true,
afterBuild: (emittedFiles) => {
emittedFiles.forEach((content, filePath) => {
if (filePath.endsWith('.d.ts')) {
const newFilePath = filePath.replace('.d.ts', '.d.cts')
fs.writeFileSync(newFilePath, content)
}
})
},
}),
],
resolve: {
alias: [{ find: '@', replacement: path.resolve(__dirname, 'src') }],
},
css: {
postcss: {
plugins: [
tailwind(),
autoprefixer(),
postcssReplace({
pattern: /(--tw|\*, ::before, ::after)/g,
data: {
'--tw': '--richtext', // Prefixing
'*, ::before, ::after': ':root', // So variables does not pollute every element
},
}),
],
},
preprocessorOptions: {
scss: {
charset: false,
api: 'modern-compiler', // or 'modern'
},
},
},
build: {
cssMinify: 'esbuild',
minify: 'esbuild',
outDir: 'lib',
sourcemap: isDev,
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
formats: ['es', 'cjs'],
},
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('@tiptap')) {
return 'tiptap'
}
if (id.includes('node_modules')) {
return 'vendor'
}
if (id.includes('src/utils')) {
return 'utils'
}
if (id.includes('src/locales')) {
return 'locales'
}
},
},
external: ['react', 'react-dom', 'react/jsx-runtime', 'katex', 'shiki', 'docx', '@radix-ui/react-dropdown-menu', '@radix-ui/react-icons', '@radix-ui/react-label', '@radix-ui/react-popover', '@radix-ui/react-separator', '@radix-ui/react-slot', '@radix-ui/react-switch', '@radix-ui/react-tabs', '@radix-ui/react-toast', '@radix-ui/react-toggle', '@radix-ui/react-tooltip', '@radix-ui/react-select', '@radix-ui/react-checkbox', 'react-colorful', 'scroll-into-view-if-needed', 'tippy.js', 'valtio', 'lucide-react', 'prosemirror-docx', 're-resizable', '@excalidraw/excalidraw', '@radix-ui/react-dialog', 'react-image-crop', 'mermaid'],
},
},
}
})