banli17 / note

学习记录
https://banli17.github.io/note/docs/intro
MIT License
17 stars 2 forks source link

rollup插件 #126

Open banli17 opened 2 years ago

banli17 commented 2 years ago
import { Plugin } from 'rollup'

const virtualId = 'virtualId.js'

export default function virtual(): Plugin {
  return {
    name: 'virtual',
    resolveId(source) {
      if (source === 'virtual') {
        return virtualId
      }
    },
    load() {
      return 'export default "virtual"'
    },
    generateBundle(options, bundle) {
      if (bundle[virtualId]) {
        delete bundle[virtualId]
      }
    },
  }
}