angularnpmangular-libraryng-packagr

How to copy the README.md file, inside an angular project before publishing it to npm


I've created a library with Angular libraries

This is my pretty default project structure

- README.md
- package.json
- angular.json
- projects
  - my-project
    - ng-package.json
    - package.json 

When publishing my library over on npm, I do run ng build my-project --configuration production && npm publish ./dist/my-project

It does correctly publish the library, but sadly, the README.md file isn't part of it.

Restrictions

  1. I know, I could copy it inside the my-project folder, but I'd prefer having only one unique README.md file.

  2. Also, I cannot delete the README.md from the root, as it will then be removed from the landing page of the GitHub repository.

  3. assets inside ng-package.json
    Sadly this does not work, as I do get Cannot read assets from a location outside of the project root. with the following code

  "assets": [
    "../../README.md"
  ]

Solution

  • I could made it work as follow

    // package.json
    "copy-files": "cp README.md dist/foo",
    "publish": "ng build foo --configuration production && npm run copy-files && npm publish ./dist/foo",
    

    then run npm run publish