const context = require.context('./', true, /\.vue$/);
const install = (Vue) => {
  context.keys().forEach((key) => {
    const component = context(key).default;
    Vue.component(component.name, component);
  });
};

Css、Sass等样式文件同样可以做到

const context = require.context('./', true, /\.scss$/);
context.keys().forEach((key) => {
  // eslint-disable-next-line
  console.log(context(key));//本行代码看似无用,却是样式文件能够成功引入的关键
});

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
猜你喜欢
  • 2022-02-22
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
相关资源
相似解决方案