mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-11-27 04:09:51 +08:00
38 lines
977 B
JavaScript
38 lines
977 B
JavaScript
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
|