mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-11-27 04:09:51 +08:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
const createVuePlugin = require('@vitejs/plugin-vue')
|
|
const getTransformedVueSrc = require('./utils/get-demo-by-path')
|
|
const createRollupCssRenderPlugin = require('./rollup-plugin-css-render')
|
|
const demoIndexTransFormPlugin = require('./vite-plugin-index-tranform')
|
|
|
|
const fileRegex = /\.(md|entry)$/
|
|
|
|
const vuePlugin = createVuePlugin({
|
|
include: [/\.vue$/, /\.md$/, /\.entry$/]
|
|
})
|
|
|
|
const createNaiveDemoVitePlugin = () => {
|
|
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 rollupCssRenderPlugin = createRollupCssRenderPlugin()
|
|
|
|
return [
|
|
demoIndexTransFormPlugin,
|
|
naiveDemoVitePlugin,
|
|
vuePlugin,
|
|
rollupCssRenderPlugin
|
|
]
|
|
}
|
|
|
|
module.exports = createNaiveDemoVitePlugin
|