// 自动注册所有指令
import Vue from 'vue'

// https://webpack.js.org/guides/dependency-management/#require-context
const requireDirective = require.context(
  // 当前目录下搜索
  '.',
  // 不包含子目录
  false,
  /.*\.js/
)

requireDirective.keys().forEach((fileName) => {
  if (fileName === './index.js') return
  const directive = requireDirective(fileName).default
  const name = fileName
    // 去除开头的 "./"
    .replace(/^\.\//, '')
    // 去掉扩展名
    .replace(/\.\w+$/, '')

  Vue.directive(name, directive)
})
