[Nx] Note for learning Nx

Proxy configuration:

When we have already fews applications running in the workspace, and we want to add 'api' layer for one applicatrion only, we can use tag

ng g @nrwl/nest:app api --frontendProject=todos

This will only allow 'todos' app to access 'api'.

 

You passed --frontendProject=todos when creating the node application. What did that argument do?

It created a proxy configuration that allows the Angular application to talk to the API in development.

To see how it works, open angular.json and find the serve target of the todos app.

复制代码
{
  "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "options": {
      "browserTarget": "todos:build",
      "proxyConfig": "apps/todos/proxy.conf.json"
    },
    "configurations": {
      "production": {
        "browserTarget": "todos:build:production"
      }
    }
  }
}
复制代码

Note the proxyConfig property.

Now open proxy.conf.json:

{
  "/api": {
    "target": "http://localhost:3333",
    "secure": false
  }
}

This configuration tells ng serve to forward all requests starting with /api to the process listening on port 3333.

 

Expose the common compoennts from library:

Sometimes, when we create library, we might forget to expose the component, this might lead to few minutes debuggin. To avoid that we can use --export tag

ng g component todos --project=ui --export

 

Running the tests:

Run npm run affected:apps, and you should see todos printed out. The affected:apps looks at what you have changed and uses the dependency graph to figure out which apps can be affected by this change.

Run npm run affected:libs, and you should see ui printed out. This command works similarly, but instead of printing the affected apps, it prints the affected libs.

 

Running the tests which failed previously:

npm run affected:test -- --only-failed

 

Running tests in parallel to speed up:

Some changes affect many projects in the repository. To speed up the testing of this change, pass --parallel.

npm run affected:test -- --parallel

 

About create NPM module in workspace:

check the source: https://nx.dev/fundamentals/develop-like-google

By default, libraries are only buildable in the context of an application.

 

To be able to build a library independently, you can pass --publishable when creating it. You can then run ng build mylib to build it, and then publish the results to an NPM registry.

 

posted @   Zhentiw  阅读(344)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-06-18 [PReact] Handle Simple Routing with preact-router
2017-06-18 [PReact] Reduce the Size of a React App in Two Lines with preact-compat
2015-06-18 [Node.js] Node.js Buffers
点击右上角即可分享
微信分享提示