mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-21 04:50:14 +08:00
38 lines
996 B
JavaScript
38 lines
996 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|entry)$/
|
|
|
|
const vuePlugin = createVuePlugin({
|
|
include: [/\.vue$/, /\.md$/, /\.entry$/]
|
|
})
|
|
|
|
const 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
|