@ ngtools / webpack ngfactory in memory compilation

I know that this was asked in different forms here, as well as in angular-cli github, but I did not find a useful answer (and the @ ngtools / webpack documentation is not quite complete).

Simply put, I wanted to test AoT with a fresh application created from angular-cli and use it outside angular-cli, so there were the following steps:

  • ng new test-app
  • ng eject
  • Minor changes in two files:
    • webpack.config.js has been modified to include entryModule
    • main.ts has been modified to load the compiled factory module instead of the standard module

I also deleted the .ngfactory files created when the application was unloaded to make a clean clean start.

What happens when i start webpack? (omitted absolute path data using [...])

ERROR in [...]/test-app/src/main.ts (4,36): Cannot find module './app/app.module.ngfactory'.

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app/app.module.ngfactory' in '[...]/test-app/src'

ngc , , , app.module.ngfactory.

, , @ngtools/webpack .ngfactory , webpack . , " ".ngfactory, , - .

, , ngc, Webpack, AoT.

main.ts: https://github.com/JimGV/angularaot/blob/master/src/main.ts

webpack: https://github.com/JimGV/angularaot/blob/master/webpack.config.js

:

new AotPlugin({
  "hostReplacementPaths": {
    "environments/environment.ts": "environments/environment.ts"
  },
  "entryModule": __dirname + "/src/app/app.module#AppModule",
  "exclude": [],
  "tsConfigPath": __dirname + "/src/tsconfig.app.json",
  "skipCodeGeneration": true
})

Mac El Capitan, node 8.1.1 Angular 4.2.4 @ngtools/webpack 1.4.1

+4

Source: https://habr.com/ru/post/1680135/


All Articles