在项目“ my-lib”中找不到配置“生产” [英] Configuration 'production' could not be found in project 'my-lib'
问题描述
我正在使用Angular 6.1.0构建库
I am building a library with Angular 6.1.0
-
ng新lib-demo
-
ng生成库my-lib
ng new lib-demo
ng generate library my-lib
所有文章都建议使用-prod
标志运行库的构建,如下所示:
All the articles advise running the build for the library with a --prod
flag like so:
ng build my-lib --prod
但是,这会引发错误
Configuration 'production' could not be found in project 'my-lib'.
这可能是正确的,因为当我查看 angular.json 时,在库项目中没有定义生产构建配置
。它仅适用于应用程序项目。
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.
以下是我在使用 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"
}
}
所以这里的问题是-prod
标志不再需要,仅运行 ng build m-lib
会生成prod版本吗?
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?
看着dist文件夹的内容看起来是这样,但我不确定100%。如果有人可以验证这一点,那就太好了。
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.
推荐答案
从6.1版开始,Angular始终对我们的库进行生产构建,即在新版本的Angular中,构建它时不再需要-prod
标志,库始终以AOT模式构建。为了确保这一点,您可以在Angular-CLI存储库中查看以下问题:
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
而本文(构建库 部分):
https://blog.angularindepth.com/creating-a-library-in-angular -6-87799552e7e5
如果您仍在使用6.0.x版(或更低版本),则需要使用-
If you are still using version 6.0.x (or lower) you will want to use the --prod flag when building your library.
您仍然可以选择通过配置
作为参数(如果需要): ng build --configuration = configuration
(请参见文档)。如有必要,您可以在 angular.json
中指定生成规则,例如,对于 production
build:
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
}
}
命令应为 ng build --configuration = production
。
这篇关于在项目“ my-lib”中找不到配置“生产”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!