2021-01-12 13:17:26 +08:00
|
|
|
const createVuePlugin = require('@vitejs/plugin-vue')
|
2021-02-02 13:11:34 +08:00
|
|
|
const getTransformedVueSrc = require('./utils/get-demo-by-path')
|
2021-01-12 13:17:26 +08:00
|
|
|
const createRollupCssRenderPlugin = require('./rollup-plugin-css-render')
|
|
|
|
const demoIndexTransFormPlugin = require('./vite-plugin-index-tranform')
|
2020-11-12 13:30:04 +08:00
|
|
|
|
2021-02-02 13:11:34 +08:00
|
|
|
const fileRegex = /\.(md|entry)$/
|
2021-01-12 13:17:26 +08:00
|
|
|
|
|
|
|
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)
|
2021-01-12 13:17:26 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
async handleHotUpdate (ctx) {
|
|
|
|
const { file } = ctx
|
|
|
|
if (fileRegex.test(file)) {
|
2021-02-02 13:11:34 +08:00
|
|
|
const code = await getTransformedVueSrc(file)
|
2021-01-12 13:17:26 +08:00
|
|
|
return vuePlugin.handleHotUpdate({
|
|
|
|
...ctx,
|
|
|
|
read: () => code
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 13:11:34 +08:00
|
|
|
|
2021-01-12 13:17:26 +08:00
|
|
|
const rollupCssRenderPlugin = createRollupCssRenderPlugin()
|
|
|
|
|
|
|
|
return [
|
|
|
|
demoIndexTransFormPlugin,
|
|
|
|
naiveDemoVitePlugin,
|
|
|
|
vuePlugin,
|
|
|
|
rollupCssRenderPlugin
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createNaiveDemoVitePlugin
|