-
Notifications
You must be signed in to change notification settings - Fork 12k
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
How to use System.import with webpack #2302
Comments
hi, |
@talsi tnx for help but i use webpack 2 and webpack 2 already support System.import the issue is because bundle generated with webpack doesnt find my 'demopackage' module in created bundle |
@zolekm - your code should work.
are you are doing your dynamic import like this ? var module = "demopackage";
System.import(module).then((data)=>{ }); in that case, webpack needs context. var module = getDynamicModuleName(); // 'demopackage';
switch (module){
case 'demopackage':
System.import('demopackage').then(data=> { });
break;
} |
@talsi tnx make sense, but problem is that i don't know which modules will need to be imported because they are defined in config which can be updated/changed. But your point is correct i already tested it and you are right, do you have any idea how to make it dynamic? Load array of dependencies which can be dynamic? |
Hi, That's a good question. I have the same problem. The way i see things you have two options.
|
Working around static analysis is an anti-pattern to the optimization that is trying to be accomplished at build time. If the files you are 'dynamically' are referencing are in your project somewhere at build time, then you do NOT want a module loader for it, you want to use static analysis. And through the future add-on system we will add for users the ability to set additional properties for context. (for webpack). |
I agree its an anti-pattern, thats why i said workaround. Any other suggestions on how to dynamically load modules? |
@TheLarkInn and @talsi tnx i currently use what @talsi suggest but in future i expect some changes in webpack so that wont be problem anymore because it is workaround, or if angular-cli will support context configuration for webpack what do you think about that @talsi? |
The CLI depends on Webpack2 for for it's |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ng --version
. If there's nothing outputted, please runin a Terminal:
node --version
and paste the result here:angular-cli: 1.0.0-beta.15
node: 6.2.2
Is there any good example how import some node_module in runtime, or/and which is right way to import dependency/reference in runtime.
With SystemJs i do that in runtime directly from node_module but with webpack i think i need to add somehow that to webpack bundle?
Example what i'm trying:
Error i got:
If i use demopack module with classic import statement than everything works
Main reason to do that and not use import 'dep' from 'some_module' is because i want to read imports from config.
The text was updated successfully, but these errors were encountered: