naive-ui/build/vite-plugin-demo.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

const createVuePlugin = require('@vitejs/plugin-vue')
2021-02-02 13:11:34 +08:00
const getTransformedVueSrc = require('./utils/get-demo-by-path')
const createRollupCssRenderPlugin = require('./rollup-plugin-css-render')
const demoIndexTransFormPlugin = require('./vite-plugin-index-tranform')
2021-02-02 13:11:34 +08:00
const fileRegex = /\.(md|entry)$/
const vuePlugin = createVuePlugin({
include: [/\.vue$/, /\.md$/, /\.entry$/]
})
const createNaiveDemoVitePlugin = () => {
const naiveDemoVitePlugin = {
name: 'demo-vite',
transform (_, id) {
2021-02-02 13:11:34 +08:00
if (fileRegex.test(id)) {
return getTransformedVueSrc(id)
}
},
async handleHotUpdate (ctx) {
const { file } = ctx
if (fileRegex.test(file)) {
2021-02-02 13:11:34 +08:00
const code = await getTransformedVueSrc(file)
return vuePlugin.handleHotUpdate({
...ctx,
read: () => code
})
}
}
}
2021-02-02 13:11:34 +08:00
const rollupCssRenderPlugin = createRollupCssRenderPlugin()
return [
demoIndexTransFormPlugin,
naiveDemoVitePlugin,
vuePlugin,
rollupCssRenderPlugin
]
}
module.exports = createNaiveDemoVitePlugin