How to export all vue components from folder with index.js?

Viewed 423

I want to export all vue components from folder. But I face error with this code

@components/index.js < code 1

import camelCase from "lodash/camelCase";
const requireModule = require.context(".", false, /\.vue$/);
const modules = {};

requireModule.keys().forEach(fileName => {
  const moduleName = camelCase(fileName.replace(/(\.\/|\.vue)/g, "")); //

  modules[moduleName] = requireModule(fileName).default;
});
export default modules;

if I export simply, it's no problem

@components/index.js < code 2

export { default as ButtonStyled } from './ButtonStyled.vue'
export { default as InputStyled } from './InputStyled.vue'

and I want to import like this:

import { InputStyled } from '@components'

Here code 2 is ok, but I need code 1. I tried with this packeage yungsilva/named-exports but not ok.

0 Answers
Related