I'd like to start using Angular components in an existing angularjs project built using gulp and would like to use downgradeModule
to create a hybrid Angular/AngularJS app.
I'm having a problem with importing AppModule from the Angular project which is not visible while bundling the AngularJS app using gulp - a browserify step complains that AppModule cannot be found:
Error: module "../new-app/src/app/app.module" not found from "Users/me/src/old-app/public/src/fake_72fafc74.js"
The module is imported like this in the AngularJS entry file:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { downgradeModule } from '@angular/upgrade/static';
import { AppModule } from '../new-app/src/app/app.module';
const bootstrapFn = (extraProviders: StaticProvider[]) => {
const platformRef = platformBrowserDynamic(extraProviders);
return platformRef.bootstrapModule(AppModule);
};
const downgradedModule = downgradeModule(bootstrapFn);
angular.module('old-angular-js-app', [..., downgradedModule])
I'm wondering how I can build the Angular app separately using the ng build
command and then make the compiled AppModule visible while bundling the angularjs app.
I thought I could call the ng build
command in a gulp task and copy the artifacts to the AngularJS dist folder:
var exec = require('child_process').exec;
gulp.task('build', function (cb) {
exec('ng build', function (err, stdout, stderr) {
// copy the artifacts to the dist folder
cb(err);
});
})
but I'm not sure how then the path to AppModule could be resolved while importing the module:
import { AppModule } from '../new-app/src/app/app.module';