Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuration 'production' could not be found in project 'my-lib'

Tags:

I am building a library with Angular 6.1.0

  • ng new lib-demo
  • ng generate library my-lib

All the articles advise running the build for the library with a --prod flag like so:

ng build my-lib --prod 

However, this throws an error

Configuration 'production' could not be found in project 'my-lib'. 

Which is probably correct because when I look at the angular.json there is no definition for a production build configuration in the library project. It is present for the application project only.

the following is what I have under the build configuration for library project that uses ng-packagr

"build": {       "builder": "@angular-devkit/build-ng-packagr:build",       "options": {         "tsConfig": "projects/my-lib/tsconfig.lib.json",         "project": "projects/my-lib/ng-package.json"       }     } 

So the question here is that is the --prod flag not required anymore and just running ng build m-lib will generate a prod build?

Looking at the contents of dist folder it looks so but I am not 100% sure. If someone could validate this, it will be great.

like image 652
Himanshu Arora Avatar asked Sep 13 '18 18:09

Himanshu Arora


People also ask

What is configuration file in Angular?

The angular.json file at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults. These are used for build and development tools provided by the Angular CLI.

What is used Angular CLI JSON?

Angular CLI uses JSON Schema to enforce the configuration schema. The Angular team created Schematics packages which are used by the CLI. We can configure the options of Schematics packages, as we please, for the root project and internal projects as well.


1 Answers

Beginning with version 6.1, Angular always does a production build of our library, i.e. in new versions of Angular we don't need the --prod flag anymore when building it, libraries are always built in AOT mode. To ensure, you can take a look at these issues in Angular-CLI repository:

https://github.com/angular/angular-cli/issues/12290

https://github.com/angular/angular-cli/issues/12226

And this article ("Building the Library" section):

https://blog.angularindepth.com/creating-a-library-in-angular-6-87799552e7e5

If you are still using version 6.0.x (or lower) you will want to use the --prod flag when building your library.

You still have an option to pass a configuration as a parameter if needed: ng build --configuration=configuration (see docs). If necessary, you can specify build rules in angular.json, for example, for production build:

"configurations": {     "production": {         // Options here     } } 

And the command should be ng build --configuration=production.

like image 185
Commercial Suicide Avatar answered Oct 20 '22 04:10

Commercial Suicide