Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic import with variable #4485

Open
The-Code-Monkey opened this issue May 3, 2022 · 2 comments
Open

Dynamic import with variable #4485

The-Code-Monkey opened this issue May 3, 2022 · 2 comments

Comments

@The-Code-Monkey
Copy link

Rollup Version

2.70.2

Operating System (or Browser)

mac os

Node Version (if applicable)

16.14.0

Link To Reproduction

https://rollupjs.org/repl/?version=2.71.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMColMjBhcyUyMFJlYWN0JTIwZnJvbSUyMCdyZWFjdCclM0IlNUNuJTJGKiUyMERZTkFNSUMlMjBJTVBPUlRTJTVDbiUyMCUyMCUyMFJvbGx1cCUyMHN1cHBvcnRzJTIwYXV0b21hdGljJTIwY2h1bmtpbmclMjBhbmQlMjBsYXp5LWxvYWRpbmclNUNuJTIwJTIwJTIwdmlhJTIwZHluYW1pYyUyMGltcG9ydHMlMjB1dGlsaXppbmclMjB0aGUlMjBpbXBvcnQlMjBtZWNoYW5pc20lNUNuJTIwJTIwJTIwb2YlMjB0aGUlMjBob3N0JTIwc3lzdGVtLiUyMColMkYlNUNuY29uc3QlMjByZXN1bHQlMjAlM0QlMjB3aW5kb3cucHJvbXB0KCU1QyUyMnBpY2slMjBzcXVhcmUlMjBvciUyMG1hdGglNUMlMjIpJTNCJTVDbiU1Q25jb25zdCUyMGZpbGUlMjAlM0QlMjBSZWFjdC5sYXp5KCgpJTIwJTNEJTNFJTIwaW1wb3J0KCU2MC4lMkYlMjQlN0JyZXN1bHQlN0QlNjApKSUzQiUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTJDJTdCJTIybmFtZSUyMiUzQSUyMm1hdGhzLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMHNxdWFyZSUyMGZyb20lMjAnLiUyRnNxdWFyZS5qcyclM0IlNUNuJTVDbmV4cG9ydCUyMCU3QmRlZmF1bHQlMjBhcyUyMHNxdWFyZSU3RCUyMGZyb20lMjAnLiUyRnNxdWFyZS5qcyclM0IlNUNuJTVDbmV4cG9ydCUyMGZ1bmN0aW9uJTIwY3ViZSUyMCh4JTIwKSUyMCU3QiU1Q24lNUN0cmV0dXJuJTIwc3F1YXJlKHgpJTIwKiUyMHglM0IlNUNuJTdEJTIyJTJDJTIyaXNFbnRyeSUyMiUzQWZhbHNlJTdEJTJDJTdCJTIybmFtZSUyMiUzQSUyMnNxdWFyZS5qcyUyMiUyQyUyMmNvZGUlMjIlM0ElMjJleHBvcnQlMjBkZWZhdWx0JTIwZnVuY3Rpb24lMjBzcXVhcmUlMjAoJTIweCUyMCklMjAlN0IlNUNuJTVDdHJldHVybiUyMHglMjAqJTIweCUzQiU1Q24lN0QlMjIlMkMlMjJpc0VudHJ5JTIyJTNBZmFsc2UlN0QlNUQlMkMlMjJvcHRpb25zJTIyJTNBJTdCJTIyZm9ybWF0JTIyJTNBJTIyZXMlMjIlMkMlMjJuYW1lJTIyJTNBJTIybXlCdW5kbGUlMjIlMkMlMjJhbWQlMjIlM0ElN0IlMjJpZCUyMiUzQSUyMiUyMiU3RCUyQyUyMmdsb2JhbHMlMjIlM0ElN0IlN0QlN0QlMkMlMjJleGFtcGxlJTIyJTNBbnVsbCU3RA==

Expected Behaviour

It should build the other files as separate files rather than not adding them to the same file.

What i really need is to be able to say all these files are to be bundled separately in the same dist folder e.g.

dist /
    icons /
       alert.js
       alert.d.ts
    index.js
   etc...

Actual Behaviour

the bundle builds my index.js with the dynamic import still written as ./icons/${name} but then the files that should be in the icons folder don't exist the types are in the icons folder but the actual code for them is not.

I kinda need to say to rollup keep the files separate.

@lukastaegert
Copy link
Member

You need to first and foremost tell Rollup what to do with that expression in the dynamic import, because it is not a static string and Rollup does not make assumptions about dynamic imports. After all, the user could type in

../../../../system/your-super-secret-passwords.json

and you do not want Rollup to bundle your entire hard drive "just in case". That being said @rollup/plugin-dynamic-import-vars is your friend.

@The-Code-Monkey
Copy link
Author

ah cheers. thats what i would be needing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants