angular-cli library create secondary entry point

后端 未结 3 1950
眼角桃花
眼角桃花 2021-02-13 18:26

I am trying to create what I believe is called a secondary entry point into my angular npm package. I want the following two entry points

@scope/data-service
@sc         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-13 18:37

    Thanks for the reply. Here is the solution I ended up with, it all revolved around setting up the index.ts and public_api.ts files correctly

    \---projects
        \---scope
            \---ngx-package
                |   karma.conf.js
                |   ng-package.json
                |   ng-package.prod.json
                |   package.json
                |   tsconfig.lib.json
                |   tsconfig.spec.json
                |   tslint.json
                |
                \---src
                    |   public_api.ts
                    |   test.ts
                    |
                    +---lib
                    |       package-client-config.ts
                    |       package-client.spec.ts
                    |       package-client.ts
                    |       package.module.ts
                    |
                    \---models
                        |   index.ts  (1)
                        |   package.json (2)
                        |   public_api.ts  (3)
                        |
                        \---src
                            |   public_api.ts  (4)
                            |
                            \---lib
                                |   model-a.ts
                                |   model-b.ts
                                |
                                \---hateoas
                                        hateoas.ts
    

    Ok so in the tree above notes the parens with numbers inside they correspond to the files below.

    1) /projects/scope/ngx-package/src/models/index.ts

    // export what ./public_api exports so we can reference models like
    // import { modelA } from './models'
    export * from './public_api';
    

    2) /projects/scope/ngx-package/src/models/package.json

    {
      "ngPackage": {}
    }
    

    3) /projects/scope/ngx-package/src/models/public_api.ts

    export * from './src/public_api';
    

    4) /projects/scope/ngx-package/src/models/src/public_api.ts

    export * from './lib/model-a';
    export * from './lib/model-b';
    export * from './lib/hateoas/hateoas';
    

    With this setup you only need to maintain your list of exports in one place. I tried a lot of other variations that didn't work this seemed to work without problem.

提交回复
热议问题