Open FredKSchott opened 3 years ago
I wonder if we could combine #2900 and #2881, expand the import.meta.glob
lexer to collect all import statements, then handle import.meta.glob
and proxy
import transforms all in one go? That sounds like it would be the most performant solution.
We could also speed up the lexer by only scanning forward from import
tokens rather than the whole file.
Also this particular use case might be solved by our upcoming import.meta.glob
feature? I'll have to test this one!
// writing the following
const langs = import.meta.glob(`../locales/*.json`);
// should produce
const langs = {
'../locales/en.json': () => import('../locales/es.json.proxy.js'),
'../locales/es.json': () => import('../locales/es.json.proxy.js')
}
Oh interesting! What if we just added a warning when we saw a complex dynamic import, telling you to use glob
instead?
import.meta.glob
can't be found in the document.
The problem that you want to solve.
Issue reported here: https://github.com/snowpackjs/snowpack/discussions/2840 We should be able to transform:
Your take on the correct solution to problem.
We could add some advanced handling to our internal transform utility to parse the expression inside of a dynamic import into an AST (with something like acorn) or even something simpler like Regex. Then, we could transform the template string based on its raw parts.
Are you willing to submit a pull request to implement this change?
This is a little tricky, but fairly self contained / a good place to start if you're looking to contribute to Snowpack!