Sniberb
Sniberb5mo ago

snowberb – 08-55 Jul 4

Is it possible to use variables while importing a module? I'm trying to dynamically import some module files but when I use variables it doesnt find the file Works:
await import(`module/lib/module.css`);
await import(`module/lib/module.css`);
Doesn't work:
await import(LIBRARY_ROUTES[library].css);
await import(LIBRARY_ROUTES[library].css);
7 Replies
lebouwski
lebouwski5mo ago
vitejs
Features
Next Generation Frontend Tooling
Sniberb
SniberbOP5mo ago
yeah we are not using vite
Sniberb
SniberbOP5mo ago
mhm, I get it but I literally have no idea about webpack :nervous: it's what we are using but idk how versions work here or whatever thanks for the info tho I knew i could do this because I did it in other projects which used more modern versions of vite and webpack
lebouwski
lebouwski5mo ago
if you put the imports in your map it may work better
const LIBRARY_ROUTES = {
foo: () => import(`module/lib/module.css`)
}
const LIBRARY_ROUTES = {
foo: () => import(`module/lib/module.css`)
}
Sniberb
SniberbOP5mo ago
true! that works wonders thanks for the idea man
reactibot
reactibot5mo ago
This thread hasn’t had any activity in 36 hours, so it’s now locked. Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1258345538378666034