Sniberb
Sniberb4mo 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
lebouwski4mo ago
vitejs
Features
Next Generation Frontend Tooling
Sniberb
Sniberb4mo ago
yeah we are not using vite
Sniberb
Sniberb4mo 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
lebouwski4mo 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
Sniberb4mo ago
true! that works wonders thanks for the idea man
reactibot
reactibot4mo 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