-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathvite.config.ts
131 lines (118 loc) · 3.99 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
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'
import { globbySync } from 'globby'
// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
const isDev = mode !== 'production';
const entry = [
path.resolve(__dirname, 'src/index.ts'),
path.resolve(__dirname, 'src/locale-bundle.ts'),
path.resolve(__dirname, 'src/components/menus/bubble-extra.ts'),
]
const files = await globbySync('src/extensions/**/*.ts', {
ignore: ['src/**/*/index.ts', 'src/**/*.spec.ts'], // Exclude .spec.ts files
});
const exports = {};
const typeVersions = {};
files.forEach((v: any) => {
const vv = v.replace('src/', '')
const [, _name, i] = vv.split('/')
if (!_name?.includes('BaseKit')) {
entry.push(path.resolve(__dirname, `src/extensions/${_name}/${_name}.ts`))
exports[`./${_name.toLowerCase()}`] = {
require: {
types: `./lib/${_name}.d.cts`,
default: `./lib/${_name}.cjs`,
},
import: {
types: `./lib/${_name}.d.ts`,
default: `./lib/${_name}.js`,
},
}
typeVersions[`./${_name.toLowerCase()}`] = [
`./lib/${_name}.d.ts`,
]
}
});
// const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
// packageJson.exports = {
// ...packageJson.exports,
// ...exports,
// }
// packageJson.typesVersions = {
// "*": {
// ...packageJson.typesVersions["*"],
// ...typeVersions,
// }
// }
// fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2))
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,
formats: ['es', 'cjs'],
fileName: (format, entryName) => {
if (format === 'es') return `${entryName}.js`;
return `${entryName}.cjs`;
},
},
rollupOptions: {
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name == "reactjs-tiptap-editor.css") return "style.css";
return assetInfo.name;
},
},
external: ['react', 'react-dom', 'react/jsx-runtime', 'katex', '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', 'lucide-react', 'prosemirror-docx', 're-resizable', '@excalidraw/excalidraw', '@radix-ui/react-dialog', 'react-image-crop', 'mermaid', 'easydrawer', 'frimousse'],
},
},
}
})