Skip to content
Advertisement

Is it possible to import *.vue files in a folder?

I hate repeating things in code. For now I am importing vue files like this in my main.js.

JavaScript

Is there a way to do same thing with less lines? Could be great if I can assign variable name from filename. Can PHP help about it? But then how to compile main.js? I did not figured out.

Advertisement

Answer

I use this script in a file named “index.js” to “export default all exported default in every file in the current folder” sort of thing:

JavaScript

Then you can import the whole directory by importing it’s name, just like this:

JavaScript

I hope this helps.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement