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()]
  })
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!