Packing the Angular project as an npm package

Now, let's learn how to export our Angular project as an npm module. We will continue to use the same vendors library that we created in the previous example:

  1. Note that we do not wish to deploy the entire application, rather, we only want to deploy the vendors library. We will use the same ng build command to build the vendors Angular project:
      ng build vendors
  1. Once the command is successfully executed, we will see that Angular will generate the compiled files for our vendors project under the dist folder, as follows:

  1. Navigate to the dist/vendors folder and run the following command:
      npm pack

We are using the npm pack command to generate a package out of the current folder, which is compiled of files from the vendors project. We should see the following output:

  1. Upon successful execution, we will see the vendors-0.01.tgz file created in the folder. We can now distribute this file as an npm package, which can be reused across any projects:

  1. Let's now give it a test drive, by installing the newly generated npm module into our application. To install the package, run the npm install command by pointing to vendors-0.0.1.tgz:
      npm install distvendorsvendors-0.0.1.tgz
  1. Upon completion, we should see the following output informing us that the package has been added:

  1. We can also verify whether the package was added successfully to the package.json file. We should see an entry in package.json displayed as follows:

Awesome! In this section, we learned how to deploy the Angular application as a standalone app and also as a composite app.

We also learned how to create a package of the Angular project that can be distributed and used in multiple Angular projects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.123.40