vite设置hook
vite项目中的 vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/guide/api-plugin.html#universal-hooks
const examplePlugin = () => {
let config
return {
name: 'read-config',
configResolved(resolvedConfig) {
// store the resolved config
config = resolvedConfig
},
buildEnd(error?: Error){
console.log("buildEnd")
},
closeBundle(){
console.log('closeBundle')
},
// use stored config in other hooks
transform(code, id) {
if (config.command === 'serve') {
// dev: plugin invoked by dev server
} else {
// build: plugin invoked by Rollup
}
}
}
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue(),examplePlugin()]
})