The code environment is browser. bundle tool is webpack. I have a router.js file like:
import foo from './views/foo.vue'
import bar from './views/bar.vue'
import zoo from './views/zoo.vue'
//use foo, bar, zoo variables
I've many '.vue' files to import like this under views folder. Is there a programmatical way to auto import all [name].vue as local variable [name]? So when I add or remove a vue file in views, I don't need to manually edit router.js file. this one seems a little dirty.
for (let name of ['foo', 'bar', 'zoo']) {
global[name] = require(`./views/${name}.vue`)
}
import- becauseimportis processed at compile time, not run time, there is no code you can write to affect it. But sincerequireis just a regular function you can write code to control it like you posted. It is not dirty at all. Sincerequireis a regular function it is perfectly OK to treat it as a regular function and call it inside a loop