Reputation: 5485
My question is straight forward
var path = './App.vue'
//var App = require(path); //THIS WILL NOT WORK
var App = require('./App.vue'); //THIS WORKS
DEMO HERE : require() does not accept javascript variable having string
If I want to make it work as to accept javascipt varibales as strings, what I should do.
Upvotes: 0
Views: 98
Reputation: 76
That's a good question. I know webpack doesn't like it when you do it because I read this:
Using require('...') with a variable vs. using a string in webpack
But I also think it's weird that this works:
var App = require(`${path}`);
I'm just curios, why do you need it to be a variable? The reason it might not work is a tool like webpack would need to know the path before it ran any code so that it can bundle all your modules.
Upvotes: 0