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

Converting dynamic import #141

Closed
enigma1 opened this issue Oct 22, 2020 · 4 comments
Closed

Converting dynamic import #141

enigma1 opened this issue Oct 22, 2020 · 4 comments

Comments

@enigma1
Copy link

enigma1 commented Oct 22, 2020

In cases where the path is dynamically I have a bit of hard time to convert it. For example

const importView = page => {
  lazy(() => import(`^/Pages/${page}`).catch(() => import('^/Pages/Error')));
}

As long as the parameters can be pre-calculated is not a problem but if they are not it can't be used. So in this example here, I can handle the second instance of import by adding an import function in the functions array of this plugin, but for the first instance direct processing is aborted because it can't simply evaluate the path.

I could handle it in the bundler it just would been good if there was a way from within the plugin to cover that case too.

@brigand
Copy link
Collaborator

brigand commented Oct 22, 2020

I agree that this would be good to support, however dynamic import has the entirety of JS available for constructing the path, so we'd have to decide on specific patterns to match.

Starting with non-tagged template literals with a leading non-empty literal section seems good. I'll take a stab at this later today.

@enigma1
Copy link
Author

enigma1 commented Oct 23, 2020

Yea pattern support would be awesome 👍

@brigand
Copy link
Collaborator

brigand commented Oct 23, 2020

The code in your sample should work now with version 6.6.0. Feel free to open another issue if it doesn't work as you expect.

@enigma1
Copy link
Author

enigma1 commented Nov 5, 2020

Just to say thanks, everything works as expected now.

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

No branches or pull requests

2 participants