-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvite.config.js
More file actions
54 lines (51 loc) · 1.23 KB
/
vite.config.js
File metadata and controls
54 lines (51 loc) · 1.23 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import svgr from 'vite-plugin-svgr'
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path'
import { readFileSync } from 'fs'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// 处理 markdown 文件的插件
const markdownPlugin = () => ({
name: 'vite-plugin-markdown',
transform(code, id) {
if (id.endsWith('.md')) {
// 读取 markdown 文件内容并作为字符串导出
const content = readFileSync(id, 'utf-8')
return {
code: `export default ${JSON.stringify(content)}`,
map: null
}
}
}
})
export default defineConfig({
base: '/',
plugins: [
react(),
markdownPlugin(),
svgr({
svgrOptions: {
icon: true,
},
}),
],
resolve: {
alias: {
'@': resolve(__dirname, './src'),
'assets': resolve(__dirname, './src/assets'),
'markdown': resolve(__dirname, './src/markdowns'),
'themes': resolve(__dirname, './src/themes'),
'muya': resolve(__dirname, './src/muya')
},
},
server: {
port: 8080,
open: true,
},
build: {
outDir: 'build',
},
assetsInclude: ['**/*.md']
})