我花了最后几周的时间来构建Typescript monorepo,可以使用Bazel构建它并将其部署到Kubernetes。但是,最后一个难题是将[[集成Angular应用程序集成到整个工作流程中,而我确实为此感到困惑。
项目 ├── WORKSPACE
├── BUILD.bazel
├── package.json
├── packages
│ ├── package1
│ ├── package2
│ └── package3
└── services
├── service1
├── service2
├── service3
+ └── angular-app
WORKSPACE
根目录中的文件BUILD.bazel
根目录中的文件package.json
BUILD.bazel
文件目标
k8s_object
添加到根BUILD.bazel
文件中,如下所示: load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects")
k8s_objects(
name = "kubernetes_deployment",
objects = [
"//services/service1",
"//services/service2",
"//services/service3",
+ "//services/angular-app"
]
)
并且当我运行bazel run :kubernets_deployment.apply
时,它应该将Angular应用程序部署到Kubernetes。就像已经完美运行的其他服务一样。部署过程涉及:
WORKSPACE
文件中>WORKSPACE
将本地packages导入到Angular源代码中>import { something } from '@project/package1';
,而不是Angular项目中的依赖项>]package.json
(我的Angular应用使用NgRx进行状态管理)package.json
(用于服务器端渲染)带有Angular CLI的面板
scss
,可以访问Bazel文件。但是我收到错误消息,告诉我找不到NgRx和本地软件包。ng build --leaveBazelFilesOnDisk
我花了最后几周的时间来构建Typescript monorepo,可以使用Bazel构建它并将其部署到Kubernetes。但是最后一个难题是将Angular应用程序集成到...
我建议在该角度示例中仔细研究与bazel相关的文件,并将所有需要的规则/函数复制到您的项目中。文件是https://github.com/flolu/cents-ideas/tree/4d444240cbbe2f8b015c4b7c85746c473bc6842b/services/client,ERROR: /home/flolu/Desktop/cents-ideas/services/client/src/app/BUILD.bazel:5:1: Compiling Angular templates (Ivy - prodmode) //src/app:app failed (Exit 1)
external/npm/node_modules/@angular/router/router.d.ts:2421:22 - error NG6002: Appears in the NgModule.imports of AppRoutingModule, but could not be resolved to an NgModule class.
This likely means that the library (@angular/router) which declares RouterModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.
2421 export declare class RouterModule {
~~~~~~~~~~~~
external/npm/node_modules/@angular/router/router.d.ts:2421:22 - error NG6003: Appears in the NgModule.exports of AppRoutingModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class.
This likely means that the library (@angular/router) which declares RouterModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.
2421 export declare class RouterModule {
~~~~~~~~~~~~
external/npm/node_modules/@angular/platform-browser/platform-browser.d.ts:44:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
This likely means that the library (@angular/platform-browser) which declares BrowserModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.
44 export declare class BrowserModule {
~~~~~~~~~~~~~
src/app/app-routing.module.ts:11:14 - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors
11 export class AppRoutingModule { }
,.bazelrc
(在每个子文件夹中),WORKSPACE
(在WORKSPACE中的http_archive上应用)。
[另外,BUILD.bazel
文件夹中有几个非常重要的文件(它们在BUILD文件中使用):rules_docker.patch
,/src
,rollup.config.js
,rxjs_shims.js
。 main.dev.ts
文件夹中有两个main.prod.ts
文件:一个用于prod,一个用于dev。
顺便说一句,此示例已经包含ngrx,因此它可能非常适合您,只需仔细查看BUILD文件及其dep中的index.html
规则即可。只需在此处添加您的部门(例如example
等)。
关于Angular Universal,Bazel现在似乎不太支持它。这是要跟踪的问题:ng_module
对于scss,如果您使用简单的CSS,那很酷,那么您可以将其插入@npm//@ngrx/store
的https://github.com/bazelbuild/rules_nodejs/issues/1126字段中,而无需从rules_sass(sass_binary,sass_library)添加其他编译步骤。从示例复制规则时,只需忽略它们。
关于项目结构,这是我从Nx迁移到Bazel的示例:assets
。这有点过时了,所以最好选择官方的。但是您可能会在其中找到一些有用的功能,即Nx中文件夹的结构。实际上,这个想法与您的想法非常相似:他们只是将服务称为应用程序,将软件包称为库,并共享通用的ng_module
。