dumber
dumber copied to clipboard
Allow for dynamic imports using non-static string
https://github.com/dumberjs/dumber/blob/13d2e1cfc1cbef58329898f745c5c7969ef795c9/lib/transformers/cjs-to-amd.js#L64 Reference #21
Hate to bring this back up, but it looks like maybe we missed a use case. The change works perfect for a static url
const viewmodel = await import('https://localhost:44301/dist/external-reports/Unbundled-2/report-view.js');
But doesn't work with a dynamic url like this
const viewmodel = await import(`https://localhost:44301/dist/external-reports/${reportCode}/report-view.js`);
I recognize that we probably can't just make it blankly accept dynamic imports all the time, because perhaps the evaluation of a dynamic string is or isn't an http request. At this point, I'm thinking that there needs to be some kind of configuration to allow import to work as expected in particular scenarios.
Agree. Config is easy to turn it on/off globally.
How to provide a per file/line config? For example, we still want use transpiled import() to load local route pages, but want to skip transpiling on some import() fetching remote resources.
It would have to be a per-line kind of config, because we might have both use cases in the same file... I hate adding comment directives in code, but that might be a requirement here? Not sure how else we can allow the native imports... Well, another options would be to provide some kind of callback config so whenever we hit an import, we can call a user defined function to determine if we want to transpile or not.
I also thought about comments. The trouble is the parser I am using is meriyah, it doesn't have comments in AST tree (comment is not defined in estree AST spec). Eslint parser can definitely look into comments.