I used this es6-module-loader
in an Angular 2
project and it worked great for loading TypeScript
modules in real time in the web-browser. Now, I am upgrading this project to Angular 6
, but here the dependencies are not met for the imports
of the loading module. For example:
declare var SystemLoader:any;
export class DemoClass {
constructor() {
var source = "export class Foo { " +
"constructor() { console.log('Created the ES6 class foo!'); } " +
"execMethod() { console.log('Executed method!') }" +
"}";
SystemLoader.module(source, {name: _name}).then(function (module: any) {
module.Foo.prototype.execMethod();
}
}
}
This previous code works in Angular 6
. It will load the module Foo
and print those lines in the Console
. But if I get the module a little complexity and add some import
like this:
declare var SystemLoader:any;
export class DemoClass {
constructor() {
var source = "import {Component} from \"@angular/core\"; " +
"export class Foo { " +
"constructor() { console.log('Created the ES6 class foo!'); } " +
"execMethod() { console.log('Executed method!') }" +
"}";
SystemLoader.module(source, {name: _name}).then(function (module: any) {
module.Foo.prototype.execMethod();
}
}
}
Then it won't work and complains with error 404 loading @angular/core
. So, in Angular 2
this was no problem because all the node_modules
required for the project where loaded by Angular
as is, but in Angular 6
it seems like all those dependencies are all shewed by Webpack
and spitted all in one big fat JavaScript
file. So, how can I get around this Webpack
simplification so that the dynamic module can load?
Edit:
Or at least a sample to migrate from es6-module-loader
(deprecated) to es-module-loader
using the same process exposed above (loading source code, compile [transpile] and render in the client's machine).
Webpack
. – Michelinamichelinesource
string? It should be "import { Component } from '@angular/core'; " + – Laquandaes6-module-loader
is deprecated so there could be something amiss with the support. Try upgrading to es-module-loader – Kelsones6-module-loader
is deprecated, but is used to work very well forAngular 2
. The main issue I have had migrating toes-module-loader
is the lack of samples, withes6-module-loader
it is quite simple as the samples I show above, butes-module-loader
has no samples likes these above, which leads me to think that this type of loading/transpile is not supported byes-module-loader
. Can you provide any sample withes-module-loader
like the ones I show above? – Michelinamicheline