forked from tusen-ai/naive-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite-plugin-demo.js
37 lines (31 loc) · 977 Bytes
/
vite-plugin-demo.js
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
const createVuePlugin = require('@vitejs/plugin-vue')
const getTransformedVueSrc = require('./utils/get-demo-by-path')
const createCssrPlugin = require('./vite-plugin-css-render')
const siteIndexTransFormPlugin = require('./vite-plugin-index-tranform')
const fileRegex = /\.(md|vue)$/
const vuePlugin = createVuePlugin({
include: [/\.vue$/, /\.md$/]
})
function createDemoPlugin() {
const naiveDemoVitePlugin = {
name: 'demo-vite',
transform(_, id) {
if (fileRegex.test(id)) {
return getTransformedVueSrc(id)
}
},
async handleHotUpdate(ctx) {
const { file } = ctx
if (fileRegex.test(file)) {
const code = await getTransformedVueSrc(file)
return vuePlugin.handleHotUpdate({
...ctx,
read: () => code
})
}
}
}
const cssrPlugin = createCssrPlugin()
return [siteIndexTransFormPlugin, naiveDemoVitePlugin, vuePlugin, cssrPlugin]
}
module.exports = createDemoPlugin