-
Notifications
You must be signed in to change notification settings - Fork 2
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
Use native dynamic imports #21
Comments
I will do static analysis, if the param looks like a remote url, skip transpiling. |
Will implement in this weekend. |
Wait, I recalled why I didn't do this. By spec, dynamic import loads an esm module. But the app here is running in AMD env, not ESM env. And I didn't implement transpiling from esm to amd at app runtime, which is required for this to work. Alternatively you can use requirejs paths config to map some module if prefix to a remote url, then use requirejs() directly to load remote module. |
Maybe I don't need to transpile esm to amd, because import will handle execution of the remote file. |
I guess your remote file is in amd format? Because otherwise I don't know how it can handle import {computedFrom} from 'aurelia-framework'; From esm which the app is running in amd. |
https://github.com/3cp/dr-paths In my production app, I am using special dumber-module-loader (an implementation of requirejs, used in every dumber app) api to load additional bundle (not just a module) at runtime. I use this architect to support plugins (plugin contains both backend logic and a frontend ui bundle) in Buttonwood app. The special api not only loads the additional bundle, but also put it behind a namespace to prevent module id pollution. There is a simple demo with limited documentation. https://dumber.js.org/runtime-app-composition |
So, a little clarification on what exactly I'm trying to do. |
Totally just playing around with it, but in the |
You can try go into dumber/lib/transformers/cjs-to-amd.js Lines 47 to 58 in d832ce8
Then do To load esm source code, I think you know the limitations: client has to use JS syntax browser can understand. For example, decorator would not work. Another limitation is import statement would not simply work. In short, it could work as long as client code has no import statement. Import of 3rd party libs might work. |
Yeah, this is what I've been playing with let hasDynamicImport = false;
traverse(parsed, node => {
if (node.type === 'Import' || node.type === 'ImportExpression') {
hasDynamicImport = true;
try {
new URL(node.source.value);
log.info('found dynamic import, not converting')
} catch (e) {
m.replace(node.start, node.start + 6, 'imp0r_');
}
}
}); Seems to be working well so far |
I agree. I will make the change. BTW, URL doesn't know this one?
I can always use regex. |
I was using the built in Node URL functionality: https://nodejs.org/api/url.html |
v1.14.1 is released. |
I'm wanting to use native dynamic imports in my code, however, they get transpired to use requirejs (which in my case fails because I'm using a url to import, not a module id).
For example, this
is being transpired to this
Is it possible to use the native dynamic import syntax with DumberJS? Am I missing a configuration somewhere, or is this a new feature request?
The text was updated successfully, but these errors were encountered: