Is it possible to import multiple Vue plugins using a loop? To avoid typing all files manually

Viewed 135

I would like to replace this part of code with some loop that will import all .js files from a specified directory (plugins in this example).

import AlertPlugin from '@/plugins/AlertPlugin';
Vue.use(AlertPlugin);

import AxiosPlugin from '@/plugins/AxiosPlugin';
Vue.use(AxiosPlugin);

import ConfigPlugin from '@/plugins/ConfigPlugin';
Vue.use(ConfigPlugin);

import TranslationPlugin from '@/plugins/TranslationPlugin';
Vue.use(TranslationPlugin);
1 Answers

Solved with babel-plugin-wildcard

import * as plugins from './plugins/';
Object.keys(plugins).forEach(key => {
   Vue.use(plugins[key]);
});
Related