aminpaks / typescript-library-bundler

Bundles a Typescript library, and makes it ready to ship for ES6, ES5, CommonJS and UMD
MIT License
6 stars 1 forks source link

TSB genertaed lib from scoped package not AoT compatible #20

Closed arpit-agarwal closed 6 years ago

arpit-agarwal commented 6 years ago

When we generate a lib for scoped package using tsb. The metadata.json changes flatModuleID to safe-package name rather than actual package-name. This cause AoT to not find the module.

ERROR in ./apps/app/src/app/app.module.ngfactory.js
Module not found: Error: Can’t resolve ‘mycompany-auth’ in ‘/Users/system/projects/ngseed/apps/app/src/app’
 @ ./apps/app/src/app/app.module.ngfactory.js 23:10-32
 @ ./apps/app/src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./apps/app/src/main.ts

However when we updated tsconfig.json to pass flatModuleID same as package-name then error disappears

  "angularCompilerOptions" : {
    "flatModuleId": "@mycompany/auth"
  }

Here is snippet of metadata.json (before change)

{
.....
 "origins": {
  //entries of file
  },
  "importAs": "mycompany-auth"
}

Here is snippet of metadata.json after changes

{
.....
 "origins": {
  //entries of file
  },
  "importAs": "@mycompany/auth"
}

I think we need a change here https://github.com/aminpaks/typescript-library-bundler/blob/master/src/config-helpers.ts#L71 We should pass raw module id to https://github.com/aminpaks/typescript-library-bundler/blob/master/src/config-helpers.ts#L47 and convert to safe-id for usage at this place https://github.com/aminpaks/typescript-library-bundler/blob/master/src/config-helpers.ts#L60

I can create a PR for the change if required

aminpaks commented 6 years ago

Hi,

Yes please go ahead and make a PR.