Angular-cli ng generate library does not work

Asked

Viewed 446 times

1

I have a design in version 5 of the angular, which generates a library using the rollup and works properly. But I’m on the migration from version 5 to version 6 of the angular and wanted to use the angular-cli, which already generates a library in the same pattern as the rollup. But when copying the code into src/app and running the ng generate library command, only a new project folder is created with a generic project, none of my files are automatically copied to the project folder. I would like to know how to generate a new library, using angular-cli in version 6, with the files inside src/app.

  • you even made the migration from 5 to 6? I don’t know the size of your project... but if it is feasible create a new project in the version with the CLI and copy only rule code and such... still I believe you will have to adjust something before generating the lib

  • Yes that’s exactly what I did, it’s easier to generate a new project with cli and copy only the code. Yes I can make some adjustments and it worked.

1 answer

1

The solution to the problem described above is found on this website: Angular-cli library. This site describes step by step how to transform a functional library into angular 6 with angular-cli.

1 - create a project with ng new .

2 - use ng generate library command .

3 - import files from your project into the Projects//lib folder

4 - Rename the public_api.ts file to index.ts.

5 - Inside the ng-pakage.json file change the public_api name to index.

6 - In tsconfig.json file, modify within path -> add path /src.

7 - Run the library with the ng build command .

If everything is configured correctly, a library will be generated within dist. This can be imported into other projects.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.