惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threat Research - Cisco Blogs
A
Arctic Wolf
S
Securelist
O
OpenAI News
T
Threatpost
Forbes - Security
Forbes - Security
N
News and Events Feed by Topic
S
Secure Thoughts
H
Heimdal Security Blog
S
Security Affairs
P
Privacy International News Feed
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
S
Security @ Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
T
Tailwind CSS Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hacker News: Ask HN
Hacker News: Ask HN
T
Troy Hunt's Blog
S
SegmentFault 最新的问题
腾讯CDC
V
Visual Studio Blog
Last Week in AI
Last Week in AI
H
Hacker News: Front Page
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Project Zero
Project Zero
WordPress大学
WordPress大学
NISL@THU
NISL@THU
博客园 - 【当耐特】
博客园 - Franky
Webroot Blog
Webroot Blog
博客园_首页
T
Tenable Blog
雷峰网
雷峰网
Google Online Security Blog
Google Online Security Blog
阮一峰的网络日志
阮一峰的网络日志
V2EX - 技术
V2EX - 技术
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
The Hacker News
The Hacker News

Nx Blog

Sharing Tailwind CSS Styles Across Apps in a Monorepo | Nx Blog How SiriusXM Stays Competitive by Iterating and Getting to Market Fast | Nx Blog Agentic Experience Is the New Developer Experience | Nx Blog Nx Joins the Linux Foundation and the Agentic AI Foundation | Nx Blog A Monorepo Is NOT a Monolith | Nx Blog Why we deleted (most of) our MCP tools | Nx Blog Teach Your AI Agent How to Work in a Monorepo | Nx Blog How Broadcom stays efficient and nimble with monorepos | Nx Blog Why Monorepos are King in the Age of AI | Nx Blog Nx 2026 Roadmap: Expanding Agent Autonomy, Improving Performance, Better Polyglot and More | Nx Blog End to End Autonomous AI Agent Workflows with Nx | Nx Blog Autonomous Agents at Scale | Nx Blog Scaling 700+ Projects: How Nx Became a 'No-Brainer' for Caseware | Nx Blog Configure Tailwind v4 with Angular in an Nx Monorepo | Nx Blog The Missing Multiplier for AI Agent Productivity | Nx Blog A Year of Nx Webinars | Nx Blog Wrapping Up 2025 | Nx Blog Nx 22.3 Release: Angular 21 Support, tsgo Compiler, and Prettier v3 | Nx Blog Nx Cloud Release: Agent Resource Usage | Nx Blog Nx Platform Outperforms DIY Cache by 5x | Nx Blog An Nx Carol: Past, Present, and Future of Your Monorepo | Nx Blog Nx 22.1 Release: Terminal UI on Windows, Storybook 10, Vitest 4, and more! | Nx Blog The Compounding Effect: How Nx Features Multiply Performance Gains | Nx Blog 10 Monorepo Myths Debunked: Separating Fact from Fiction | Nx Blog Nx Cloud Release: Enterprise Task Analytics | Nx Blog Watch and Rebuild Storybook Dependencies with Nx | Nx Blog Book - React for Enterprise: Timeless Architecture for Enterprise Apps | Nx Blog Beyond Remote Cache: Unlock 70% More CI Performance | Nx Blog Nx 22 Release: Expanding the build platform | Nx Blog What's the Point of Generating All This Code If You Can't Merge It? | Nx Blog What's New in Nx Self-Healing CI | Nx Blog Nx Highlights: Smarter AI integration, all-new graph UI, and big new versions of your favorite tools | Nx Blog Making the Case for Smarter Monorepos, and How to Not Get Fooled by Myths | Nx Blog Integrating Biome in 20 Minutes | Nx Blog S1ngularity - What Happened, How We Responded, What We Learned | Nx Blog Stop Babysitting Your PRs: Self-Healing CI Cuts Time to Green by 50% | Nx Blog UKG Unifies Their Codebase and Eliminates CI Overhead to Focus on Customer Value | Nx Blog How Git Worktrees Changed My AI Agent Workflow | Nx Blog Nx Cloud Workspace Graph: See Your Organization's Code Structure Like Never Before | Nx Blog Seamless Java Deployment in Nx Using Docker | Nx Blog Getting Mobile Into Your Monorepo: Android + Nx | Nx Blog Polyglot Projects Made Easy: Integrating Spring Boot into an Nx Workspace | Nx Blog The Journey of the Nx Plugin for Gradle: From Prototype to Production | Nx Blog Combining Predictability and Intelligence With Nx Generators and AI | Nx Blog A New UI For The Humble Terminal | Nx Blog Continuous tasks are a huge DX improvement | Nx Blog New and Improved Module Federation Experience with Nx | Nx Blog A New UI for Nx Migration | Nx Blog Custom Task Runners and Self-Hosted Caching Changes | Nx Blog Enterprise Angular Monorepo Patterns | Nx Blog Using Rspack with Angular | Nx Blog Angular Architecture Guide To Building Maintainable Applications at Scale | Nx Blog Modern Angular Testing with Nx | Nx Blog Nx Update: 20.5 | Nx Blog Are Monorepos the Answer to Better AI-Assisted Development? | Nx Blog Making Cursor Smarter with an MCP Server For Nx Monorepos | Nx Blog React Development for 2025 | Nx Blog Using Apollo GraphQL in an Nx Workspace | Nx Blog Angular State Management for 2025 | Nx Blog Tailoring Nx for Your Organization | Nx Blog Nx Cloud Pipelines Come To Nx Console | Nx Blog Define the relationship with monorepos | Nx Blog See your affected project graph in Nx Cloud | Nx Blog Handling CORS In Your Workspace | Nx Blog Improve your architecture and CI pipeline times with Nx projects | Nx Blog Announcing Nx 20 | Nx Blog Introducing Nx Powerpack | Nx Blog Nx 19.5 is here! Stackblitz, Bun, Incremental Builds for Vite, Gradle Test Atomizer | Nx Blog Introducing Explain with AI | Nx Blog Nx Enterprise Podcast Episode 2: Tine Kondo | Nx Blog Monorepos and CI can be a Mess - Here's How Nx and Nx Cloud Fixed It | Nx Blog Nx Enterprise Podcast Episode 1: Hicham El Hammouchi | Nx Blog Nx 19.0 Release!! | Nx Blog Manage Your Gradle Project using Nx | Nx Blog Making the Argument for Monorepos | Nx Blog Reliable CI. A new execution model fixing both flakiness and slowness | Nx Blog Monorepos - Why Speed Matters | Nx Blog Nx Agents Walkthrough: Effortlessly Fast CI Built for Monorepos | Nx Blog Launch Nx Week Recap | Nx Blog Versioning and Releasing Packages in a Monorepo | Nx Blog Fast, Effortless CI | Nx Blog Introducing @nx/nuxt Enhanced Nuxt.js Support in Nx | Nx Blog What if Nx Plugins Were More Like VSCode Extensions | Nx Blog Monorepos: the Benefits, Challenges, and Importance of Tooling Support | Nx Blog Nx — Highlights of 2023 | Nx Blog Nx 17.2 Update | Nx Blog Unit Testing Expo Apps With Jest | Nx Blog Nx Docs AI Assistant | Nx Blog State Management Nx React Native/Expo Apps with TanStack Query and Redux | Nx Blog Nx 17 has Landed | Nx Blog Nx Conf 2023 — Recap | Nx Blog Nx Raises $16M Series A | Nx Blog Introducing Playwright Support for Nx | Nx Blog Nx 16.8 Release!!! | Nx Blog Step-by-Step Guide to Creating an Expo Monorepo with Nx | Nx Blog Qwikify your Development with Nx | Nx Blog Create Your Own create-react-app CLI | Nx Blog Storybook Interaction Tests in Nx | Nx Blog Evergreen Tooling — More than Just CodeMods | Nx Blog A Practical Guide on Effective AI Use - AI as Your Peer Programmer | Nx Blog
Nx Console gets Lit | Nx Blog
Max Kless · 2023-06-30 · via Nx Blog

Over the last few weeks, we rebuilt one of Nx Console's most liked features from the ground up: The Generate UI. It looks better, loads faster, and preliminary research shows using it makes you happier, too ;)

You can use it today by installing the latest version of Nx Console for VSCode and JetBrains IDEs! 🎉🎉🎉

If you're curious to learn more about the rewrite and the motivations behind it, this is the blog post for you! We'll touch on these topics and more:

  • Why did we choose to rewrite?
  • What's Lit and why did we use it over Angular?
  • How did the rewrite go and what Lit features were important for us?
  • What does the performance look like before and after?

Background: Why Migrate from Angular to Lit?

A Short History of Nx Console

Let's go back in time: Nx Console has been around for a while. It first launched in 2018 — then called Angular Console — as a standalone Electron app which let you run Angular schematics and builders from a graphical interface. Of course, it was built with Angular and looked something like this:

Screenshot of the original Angular Console electron app

In 2019, it was ported to a VSCode extension with the now familiar UI and support for the standalone app was dropped.

In 2020, support for the entire Nx ecosystem was added, it was renamed to Nx Console and an amazing transformation began: Today, Nx Console is much more than just a single form — it tightly integrates Nx into your IDE, gives you the overview of your projects that you need and puts your task-running just a click away.

Rewriting in Lit

This evolution brought significant improvements to the usability of Nx Console and the value we could provide to developers, but not without presenting its own set of challenges. Inevitably, the codebase grew complex and convoluted over time — the context in which it ran changed, the scope of the product changed, yet the technology remained the same. Adding small features or fixing bugs became increasingly time consuming, and every PR compounded the problem.

The UI looked somewhat outdated and had been built with only VSCode in mind — which became painfully obvious when support for JetBrains IDEs was added. While the web-based nature of the Generate UI allowed us to reuse the code in the new environment, the design looked out of place.

In addition, we started questioning our usage of Angular. Angular is a great framework for building web apps, and in the original context of Angular Console, it made a lot of sense: A tool built by and for Angular engineers — of course it's written in Angular. But things changed, and Angular started to feel overkill for what we needed. Angular has a huge number of features right out of the box. But for our simple form, we didn't need routing, http requests or modules to organize our code. The amount of boilerplate and overhead Angular introduces is significant.

So, ultimately, we decided to pull the plug and rewrite the entire thing in Lit.

Lit is a lightweight framework built on top of web components and "adds just what you need to be happy and productive: reactivity, declarative templates and a handful of thoughtful features to reduce boilerplate and make your job easier" (taken from their docs). We had used it before to build the Nx Cloud view and were happy with the simple setup and great DX. So the decision to reuse it here was an easy one, since it allowed us to reuse code, build tooling and expertise. The rewrite also gave us the opportunity to improve the design for both supported IDEs and give the entire UI a clean, new coat of paint.

Screenshot of the reworked generate ui

Before I dive deeper into specifics, let's have a look at the general architecture of Nx Console first.

Nx Console Architectural Overview

Nx Console is composed of 3 core parts:

  • The nxls is a language server based on the Language Server Protocol (LSP) and acts as the "brain" of Nx Console. It analyzes your Nx workspace and provides information on it, including code completion and more.
  • The Generate UI is the form-based view for running Nx generators.
  • The platform-specific wrappers. These are written in Typescript and Kotlin and connect the rest of Nx Console to IDE-specific APIs. Having the other parts separate greatly reduces the amount of duplicated code we have to write in order to support multiple IDEs

This architecture's modularity meant we could quickly switch out the Generate UI for a new version without significantly impacting the rest of the codebase — only the parts that actually render the UI and communicate with it had to be adjusted slightly. It also allowed us to ensure backward compatibility: the old generate UI is still available via a feature toggle in the settings.

If you want to dive deeper, there are many more resources on the architecture of Nx Console and how it's built:

Migrating to Lit: Step by Step

To rebuild our UI, we first needed a new Lit app to work on. While there's no native Nx plugin for Lit, generating the code we need was still very straightforward:

nx generate @nx/web:app apps/generate-ui-v2

This generates an entire project for us, with a tsconfig.json, index.html, main.ts, and a project.json, where our Nx-specific config lives.

I also installed a couple of dependencies:

  • The @nx/esbuild plugin because I like fast build times 🏎️
  • TailwindCSS because I don't like writing CSS 🤫
  • @vscode/webview-ui-toolkit because it does all of the VSCode work for me 🤖

This is really where Nx shines, because it allows you to take these tools and quickly patch them together and build a pipeline that does exactly what you need. And it also allows you to think about your workspace visually. This is what this is what my task graph for building the Lit app ultimately looks like:

Nx task graph for building the Lit webview

You can see three build steps:

  • generate-ui-v2:_build uses esbuild to bundle my Lit components written in Typescript and spits out a main.js file
  • generate-ui-v2:extract-dependencies copies the third party assets we need into the dist folder. Right now it's just codicons .css and .ttf files.
  • generate-ui-v2:build finally runs tailwind over the bundled code. This could also be done with postCss or a custom esbuild plugin but running tailwind directly is the easier, so why complicate things?

💡 There are different ways to generate this visualisation for your own workspaces:

  • In VSCode, use the Nx Project View or the Nx: Focus task in Graph action
  • In JetBrains IDEs, use the Nx Toolwindow or context menus
  • In the command line, run nx build {{your project}} --graph

In the bigger context of Nx Console, here's what happens when you build the VSCode extension:

Nx task graph for building the VSCode extension

You can see that we're still building both the new & old generate UI as well as the Nxls and the Nx Cloud webview before combining them all into one VSCode extension artifact.

Building the Form

Lit is a very small library that provides useful abstractions over browser-native features like web components and messages. Here's what a simple Lit component, written with Typescript, looks like:

@customElement('root-element')
export class Root extends LitElement {
  render() {
    return html`<p>Hello World</p>`;
  }
}
<!DOCTYPE html>
<html lang="en">
  <body>
    <script type="module" src="main.js"></script>
    <root-element></root-element>
  </body>
</html>

If you need to pass information up the DOM, you use normal events and you can set properties to send information to descendants. Check out the Lit Docs to learn more about how the render() method works, how to leverage reactivity, the shadow DOM and so much more.

💡 All code samples in this section have been adapted for brevity and clarity. So you won't find this exact code anywhere, but it demonstrates the concepts well.

Communicating with the IDE — using Reactive Controllers

To communicate with the host IDE, we were able to reuse almost all the logic from the previous UI (for more details, see Communicating with IntelliJ from the last blog post). Instead of a service that exposes observables that our component can consume, we used a Reactive Controller. Controllers are a neat feature of Lit — they hook into a component and can request DOM updates on their behalf. This eliminates the need for observable streams and subscriptions while keeping the communication code self-contained. Look at this example:

@customElement('root-element')
export class Root extends LitElement {
  icc: IdeCommunicationController;

  constructor() {
    super();
    this.icc = new IdeCommunicationController(this);
  }
  render() {
    return html`${JSON.stringify(this.icc.generatorSchema)}`;
  }
}

ide-communication-controller.ts

// ide-communication-controller.ts
export class IdeCommunicationController implements ReactiveController {
  generatorSchema: GeneratorSchema | undefined;
  constructor(private host: ReactiveControllerHost) {}
  // ...
  private handleMessageFromIde(message: InputMessage) {
    // ...
    this.generatorSchema = message.payload;
    this.host.requestUpdate();
  }
}

You can see that root-element can really just deal with rendering the form contents, delegating communicating with the IDE and when to update the DOM to the controller.

Rendering the form fields — using Mixins

The core part of the UI is the form. We built all kinds of inputs: text fields, checkboxes, (multi-) select boxes and array fields. While those each have unique implementations, displaying them is also going to take a lot of repeated code. Every fields needs a label and description. Every field needs to know about its validation state, how dispatch change events and what aria attributes to set. In order to keep this code clean and DRY, we used Class Mixins. Mixins aren't really a Lit-specific feature, but I don't see them used much in other frameworks. A mixin is essentially a factory that takes a class and returns another, modified class. Check out this example:

const Field = (superClass) =>
  class extends superClass {
    // we can define (reactive) properties that every field is going to need
    @property()
    option: Option;
    protected get fieldId(): string {
      return `${this.option.name}-field`;
    }

    // we can define methods that should be available to all fields
    dispatchValue(value: string) {
      // ...
    }
  };
const FieldWrapper = (superClass) =>
  class extends superClass {
    // we can define a render() method so that fields are all rendered the same
    protected render() {
      return html` <label for="${this.fieldId}">${this.option.name}</label>
        <p>${this.option.description}</p>
        ${this.renderField()}`;
    }
  };
@customElement('input-field')
export class InputField extends FieldWrapper(Field(LitElement)) {
  renderField() {
    return html` <input
      id="${this.fieldId}"
      @input="${(e) => this.dispatchValue(e.target.value)}"
    />`;
  }
}

You can see that each component and mixin deals with a specific subset of the overall logic, keeping our code cleanly separated and reusable. A checkbox, for example, is a special case because it's layout on the page is slightly different — no problem, we simply wrote a CheckboxWrapper with some modifications without having to worry about changing the checkbox logic itself.

💡 Properly typing mixins is complicated so I left that part out. Refer to Mixins in Typescript to learn more or check out our source code on GitHub.

Injecting Services & Data — Lit Context

If you're coming from the Angular world, you probably appreciate the great dependency injection (DI) mechanism they have. You can centrally define some services and reuse them across your app, without thinking about passing on props from component to component — the DI system takes care of it. Lit provides something similar via the []@lit-labs/context](https://lit.dev/docs/data/context/) package. It's based on the Context Community Protocol and similar to React's context API.

Under the hood, it still works with normal browser events, but it abstracts it away from you so you can easily share data and services across your app.

The Generate UI is rendered in both VSCode and JetBrains IDEs. In order to look appropriate, components need to know which environment they're in and adjust styling accordingly. Instead of passing this information from component to component, we can make it available contextually! And with a proper mixin, reading the editor context only has to be implemented once, too.

Have a look at the following example:

export const editorContext = createContext<'vscode' | 'intellij'>(
  Symbol('editor')
);

const EditorContext = (superClass) =>
  class extends superClass {
    @consume({ context: editorContext })
    @state()
    editor: 'vscode' | 'intellij';
  };

ide-communication-controller.ts

export class IdeCommunicationController implements ReactiveController {
  // ...
  constructor(private host: ReactiveElement) {
    const editor = isVscode() ? 'vscode' : 'intellij';
    // provide the context to all DOM children of the host element
    new ContextProvider(host, {
      context: editorContext,
      initialValue: editor,
    });
  }
}
@customElement('some-component')
export class SomeComponent extends EditorContext(LitElement) {
  render() {
    return html`<p>I am rendered in ${this.editor}</p>`;
  }
}

VSCode Webview UI Toolkit

As we mentioned above, a big part of why we rewrote the UI is that it looked quite out of place in JetBrains IDEs. It was still useful, of course, but it's important to make sure the form feels right.

In VSCode, this is very easy to achieve, thanks to the VSCode Webview UI Toolkit. It's a set of web components, provided by Microsoft, that are designed to look good and be used in VSCode webviews.

Sample image of the VSCode Webview UI Toolkit showing the different components it provides

Using it, you get the native look, a11y, and theme-aware styling for free! Thanks to everyone who built it, it's a huge help!

E2E Testing with Cypress

One big upside of using a webview is the huge Javascript ecosystem is available to you! To make sure that no regressions are introduced later on, we use Cypress. We can mock the editor communication and provide different schemas, make sure the form is rendered correctly and the right messages are sent back to the IDE.

While there's no particular Lit integration for Cypress, the tool itself is framework agnostic so it still works perfectly fine. Using the @nx/cypress executors did most of the work for us so setup was pretty quick too.

Results: Comparing Performance

There's a number of different aspects to performance we can compare between the two implementations. The biggest one by far is not really quantifiable: The maintainability and looks of the new UI. In my opinion, it looks a lot fresher and more native in both environments. We got rid of a lot of legacy code and the new version is easier to reason about and work with. But there are thing we can measure, so let's talk numbers!

Startup Time

It takes time to bootstrap a large framework like Angular, so skipping that, the UI should load quicker than before.

We measured the median time it took to render all options of the @nx/angular:application generator in both VSCode and IntelliJ. You can see that the results are pretty clear-cut, even though they are not hugely impactful.

Old UI (Angular)New UI (Lit)SpeedupVSCode65 ms39 ms~ 1.7xIntelliJ189 ms122 ms~ 1.5x

Bundle Size

As mentioned earlier, Angular comes with a lot more features out-of-the-box than Lit, so it would make sense that the built bundle will be bigger.

We were able to reduce the bundle size (w/o compression) from about 733 kB to 282 kB, which comes out to about a 2,6x decrease. Unlike a website, where the bundle needs to be shipped to users when they load a page, Nx Console users only need to download it once when installing the plugin. This means we're not affected by network speeds after installation, which makes the bundle size less critical.

💡 Because of a misconfiguration from a few Angular versions ago, the bundle size that we reported in this tweet was overly bloated. We corrected it, but Lit still came out ahead in terms of size and rendering times.

Build Time

While it might not be important to users of Nx Console, the time it takes to build the project makes a difference to us developers.

Since Lit is just javascript files that don't require a custom compiler or build tooling, we decided to use esbuild (via @nx/esbuild), which is written in Go and extremely fast. On the other hand, the old UI used the @angular-builders/custom-webpack:browser builder, which uses webpack under the hood.

We went from about 3.5 seconds to less than 2 seconds of build time, which is less of an improvement than we expected. Since we also have to run tailwind over our files, some of that additional esbuild speed seems to be relativized.

Looking Ahead

Rebuilding the UI has paved the road to reduce a lot of the maintenance burden of Nx Console. It will allow us to move even quicker on building new features to provide the best developer experience possible for you.

Specifically, the updated architecture enabled us to build a (still secret and WIP) plugin feature for Nx Console. Just like Nx, there are always going to be things that are unique to your workspace. We want to make it easy for you to extend and modify Nx Console in ways that help you make the most of using it.

So keep your eyes peeled for announcements and let us know via GitHub or Twitter if you have any ideas! We'd love to chat.

One more thing!

Nx Console is a tool by developers for developers and there's one thing we love — keyboard shortcuts. So of course we had to build some in. In addition to being keyboard-friendly and tabbable, you can do the following:

  • Cmd/Ctrl + Enter to run the generator
  • Cmd/Ctrl + Shift + Enter to start a dry run
  • Cmd/Ctrl + Shift + S to focus the search bar and look for a specific option. Just tab to get back to the form

If the prettier UI and better performance haven't convinced you, this surely will! 😉


Learn more


title: Nx Console gets Lit slug: 'nx-console-gets-lit' authors: [Max Kless] cover_image: '/blog/images/2023-06-29/featured_img.webp' tags: [nx, nx-console]


Over the last few weeks, we rebuilt one of Nx Console’s most liked features from the ground up: The Generate UI. It looks better, loads faster, and preliminary research shows using it makes you happier, too ;)

You can use it today by installing the latest version of Nx Console for VSCode and JetBrains IDEs! 🎉🎉🎉

If you’re curious to learn more about the rewrite and the motivations behind it, this is the blog post for you! We’ll touch on these topics and more:

  • Why did we choose to rewrite?
  • What’s Lit and why did we use it over Angular?
  • How did the rewrite go and what Lit features were important for us?
  • What does the performance look like before and after?

Background: Why Migrate from Angular to Lit?

A Short History of Nx Console

Let’s go back in time: Nx Console has been around for a while. It first launched in 2018 — then called Angular Console — as a standalone Electron app which let you run Angular schematics and builders from a graphical interface. Of course, it was built with Angular and looked something like this:

Screenshot of the original Angular Console electron app

In 2019, it was ported to a VSCode extension with the now familiar UI and support for the standalone app was dropped.

In 2020, support for the entire Nx ecosystem was added, it was renamed to Nx Console and an amazing transformation began: Today, Nx Console is much more than just a single form — it tightly integrates Nx into your IDE, gives you the overview of your projects that you need and puts your task-running just a click away.

Rewriting in Lit

This evolution brought significant improvements to the usability of Nx Console and the value we could provide to developers, but not without presenting its own set of challenges. Inevitably, the codebase grew complex and convoluted over time — the context in which it ran changed, the scope of the product changed, yet the technology remained the same. Adding small features or fixing bugs became increasingly time consuming, and every PR compounded the problem.

The UI looked somewhat outdated and had been built with only VSCode in mind — which became painfully obvious when support for JetBrains IDEs was added. While the web-based nature of the Generate UI allowed us to reuse the code in the new environment, the design looked out of place.

In addition, we started questioning our usage of Angular. Angular is a great framework for building web apps, and in the original context of Angular Console, it made a lot of sense: A tool built by and for Angular engineers — of course it’s written in Angular. But things changed, and Angular started to feel overkill for what we needed. Angular has a huge number of features right out of the box. But for our simple form, we didn’t need routing, http requests or modules to organize our code. The amount of boilerplate and overhead Angular introduces is significant.

So, ultimately, we decided to pull the plug and rewrite the entire thing in Lit.

Lit is a lightweight framework built on top of web components and “adds just what you need to be happy and productive: reactivity, declarative templates and a handful of thoughtful features to reduce boilerplate and make your job easier” (taken from their docs). We had used it before to build the Nx Cloud view and were happy with the simple setup and great DX. So the decision to reuse it here was an easy one, since it allowed us to reuse code, build tooling and expertise. The rewrite also gave us the opportunity to improve the design for both supported IDEs and give the entire UI a clean, new coat of paint.

Screenshot of the reworked generate ui

Before I dive deeper into specifics, let’s have a look at the general architecture of Nx Console first.

Nx Console Architectural Overview

Nx Console is composed of 3 core parts:

  • The nxls is a language server based on the Language Server Protocol (LSP) and acts as the “brain” of Nx Console. It analyzes your Nx workspace and provides information on it, including code completion and more.
  • The Generate UI is the form-based view for running Nx generators.
  • The platform-specific wrappers. These are written in Typescript and Kotlin and connect the rest of Nx Console to IDE-specific APIs. Having the other parts separate greatly reduces the amount of duplicated code we have to write in order to support multiple IDEs

This architecture’s modularity meant we could quickly switch out the Generate UI for a new version without significantly impacting the rest of the codebase — only the parts that actually render the UI and communicate with it had to be adjusted slightly. It also allowed us to ensure backward compatibility: the old generate UI is still available via a feature toggle in the settings.

If you want to dive deeper, there are many more resources on the architecture of Nx Console and how it’s built:

Migrating to Lit: Step by Step

To rebuild our UI, we first needed a new Lit app to work on. While there’s no native Nx plugin for Lit, generating the code we need was still very straightforward:

nx generate @nx/web:app apps/generate-ui-v2

This generates an entire project for us, with a tsconfig.json, index.html, main.ts, and a project.json, where our Nx-specific config lives.

I also installed a couple of dependencies:

  • The @nx/esbuild plugin because I like fast build times 🏎️
  • TailwindCSS because I don’t like writing CSS 🤫
  • @vscode/webview-ui-toolkit because it does all of the VSCode work for me 🤖

This is really where Nx shines, because it allows you to take these tools and quickly patch them together and build a pipeline that does exactly what you need. And it also allows you to think about your workspace visually. This is what this is what my task graph for building the Lit app ultimately looks like:

Nx task graph for building the Lit webview

You can see three build steps:

  • generate-ui-v2:_build uses esbuild to bundle my Lit components written in Typescript and spits out a main.js file
  • generate-ui-v2:extract-dependencies copies the third party assets we need into the dist folder. Right now it’s just codicons .css and .ttf files.
  • generate-ui-v2:build finally runs tailwind over the bundled code. This could also be done with postCss or a custom esbuild plugin but running tailwind directly is the easier, so why complicate things?

💡 There are different ways to generate this visualisation for your own workspaces:

  • In VSCode, use the Nx Project View or the Nx: Focus task in Graph action
  • In JetBrains IDEs, use the Nx Toolwindow or context menus
  • In the command line, run nx build {{your project}} --graph

In the bigger context of Nx Console, here’s what happens when you build the VSCode extension:

Nx task graph for building the VSCode extension

You can see that we’re still building both the new & old generate UI as well as the Nxls and the Nx Cloud webview before combining them all into one VSCode extension artifact.

Building the Form

Lit is a very small library that provides useful abstractions over browser-native features like web components and messages. Here’s what a simple Lit component, written with Typescript, looks like:

@customElement('root-element')
export class Root extends LitElement {
  render() {
    return html`<p>Hello World</p>`;
  }
}
<!DOCTYPE html>
<html lang="en">
  <body>
    <script type="module" src="main.js"></script>
    <root-element></root-element>
  </body>
</html>

If you need to pass information up the DOM, you use normal events and you can set properties to send information to descendants. Check out the Lit Docs to learn more about how the render() method works, how to leverage reactivity, the shadow DOM and so much more.

💡 All code samples in this section have been adapted for brevity and clarity. So you won’t find this exact code anywhere, but it demonstrates the concepts well.

Communicating with the IDE — using Reactive Controllers

To communicate with the host IDE, we were able to reuse almost all the logic from the previous UI (for more details, see Communicating with IntelliJ from the last blog post). Instead of a service that exposes observables that our component can consume, we used a Reactive Controller. Controllers are a neat feature of Lit — they hook into a component and can request DOM updates on their behalf. This eliminates the need for observable streams and subscriptions while keeping the communication code self-contained. Look at this example:

@customElement('root-element')
export class Root extends LitElement {
  icc: IdeCommunicationController;

  constructor() {
    super();
    this.icc = new IdeCommunicationController(this);
  }
  render() {
    return html`${JSON.stringify(this.icc.generatorSchema)}`;
  }
}

ide-communication-controller.ts

// ide-communication-controller.ts
export class IdeCommunicationController implements ReactiveController {
  generatorSchema: GeneratorSchema | undefined;
  constructor(private host: ReactiveControllerHost) {}
  // ...
  private handleMessageFromIde(message: InputMessage) {
    // ...
    this.generatorSchema = message.payload;
    this.host.requestUpdate();
  }
}

You can see that root-element can really just deal with rendering the form contents, delegating communicating with the IDE and when to update the DOM to the controller.

Rendering the form fields — using Mixins

The core part of the UI is the form. We built all kinds of inputs: text fields, checkboxes, (multi-) select boxes and array fields. While those each have unique implementations, displaying them is also going to take a lot of repeated code. Every fields needs a label and description. Every field needs to know about its validation state, how dispatch change events and what aria attributes to set. In order to keep this code clean and DRY, we used Class Mixins. Mixins aren’t really a Lit-specific feature, but I don’t see them used much in other frameworks. A mixin is essentially a factory that takes a class and returns another, modified class. Check out this example:

const Field = (superClass) =>
  class extends superClass {
    // we can define (reactive) properties that every field is going to need
    @property()
    option: Option;
    protected get fieldId(): string {
      return `${this.option.name}-field`;
    }

    // we can define methods that should be available to all fields
    dispatchValue(value: string) {
      // ...
    }
  };
const FieldWrapper = (superClass) =>
  class extends superClass {
    // we can define a render() method so that fields are all rendered the same
    protected render() {
      return html` <label for="${this.fieldId}">${this.option.name}</label>
        <p>${this.option.description}</p>
        ${this.renderField()}`;
    }
  };
@customElement('input-field')
export class InputField extends FieldWrapper(Field(LitElement)) {
  renderField() {
    return html` <input
      id="${this.fieldId}"
      @input="${(e) => this.dispatchValue(e.target.value)}"
    />`;
  }
}

You can see that each component and mixin deals with a specific subset of the overall logic, keeping our code cleanly separated and reusable. A checkbox, for example, is a special case because it’s layout on the page is slightly different — no problem, we simply wrote a CheckboxWrapper with some modifications without having to worry about changing the checkbox logic itself.

💡 Properly typing mixins is complicated so I left that part out. Refer to Mixins in Typescript to learn more or check out our source code on GitHub.

Injecting Services & Data — Lit Context

If you’re coming from the Angular world, you probably appreciate the great dependency injection (DI) mechanism they have. You can centrally define some services and reuse them across your app, without thinking about passing on props from component to component — the DI system takes care of it. Lit provides something similar via the []@lit-labs/context](https://lit.dev/docs/data/context/) package. It’s based on the Context Community Protocol and similar to React’s context API.

Under the hood, it still works with normal browser events, but it abstracts it away from you so you can easily share data and services across your app.

The Generate UI is rendered in both VSCode and JetBrains IDEs. In order to look appropriate, components need to know which environment they’re in and adjust styling accordingly. Instead of passing this information from component to component, we can make it available contextually! And with a proper mixin, reading the editor context only has to be implemented once, too.

Have a look at the following example:

export const editorContext = createContext<'vscode' | 'intellij'>(
  Symbol('editor')
);

const EditorContext = (superClass) =>
  class extends superClass {
    @consume({ context: editorContext })
    @state()
    editor: 'vscode' | 'intellij';
  };

ide-communication-controller.ts

export class IdeCommunicationController implements ReactiveController {
  // ...
  constructor(private host: ReactiveElement) {
    const editor = isVscode() ? 'vscode' : 'intellij';
    // provide the context to all DOM children of the host element
    new ContextProvider(host, {
      context: editorContext,
      initialValue: editor,
    });
  }
}
@customElement('some-component')
export class SomeComponent extends EditorContext(LitElement) {
  render() {
    return html`<p>I am rendered in ${this.editor}</p>`;
  }
}

VSCode Webview UI Toolkit

As we mentioned above, a big part of why we rewrote the UI is that it looked quite out of place in JetBrains IDEs. It was still useful, of course, but it’s important to make sure the form feels right.

In VSCode, this is very easy to achieve, thanks to the VSCode Webview UI Toolkit. It’s a set of web components, provided by Microsoft, that are designed to look good and be used in VSCode webviews.

Sample image of the VSCode Webview UI Toolkit showing the different components it provides

Using it, you get the native look, a11y, and theme-aware styling for free! Thanks to everyone who built it, it’s a huge help!

E2E Testing with Cypress

One big upside of using a webview is the huge Javascript ecosystem is available to you! To make sure that no regressions are introduced later on, we use Cypress. We can mock the editor communication and provide different schemas, make sure the form is rendered correctly and the right messages are sent back to the IDE.

While there’s no particular Lit integration for Cypress, the tool itself is framework agnostic so it still works perfectly fine. Using the @nx/cypress executors did most of the work for us so setup was pretty quick too.

Results: Comparing Performance

There’s a number of different aspects to performance we can compare between the two implementations. The biggest one by far is not really quantifiable: The maintainability and looks of the new UI. In my opinion, it looks a lot fresher and more native in both environments. We got rid of a lot of legacy code and the new version is easier to reason about and work with. But there are thing we can measure, so let’s talk numbers!

Startup Time

It takes time to bootstrap a large framework like Angular, so skipping that, the UI should load quicker than before.

We measured the median time it took to render all options of the @nx/angular:application generator in both VSCode and IntelliJ. You can see that the results are pretty clear-cut, even though they are not hugely impactful.

Old UI (Angular)New UI (Lit)SpeedupVSCode65 ms39 ms~ 1.7xIntelliJ189 ms122 ms~ 1.5x

Bundle Size

As mentioned earlier, Angular comes with a lot more features out-of-the-box than Lit, so it would make sense that the built bundle will be bigger.

We were able to reduce the bundle size (w/o compression) from about 733 kB to 282 kB, which comes out to about a 2,6x decrease. Unlike a website, where the bundle needs to be shipped to users when they load a page, Nx Console users only need to download it once when installing the plugin. This means we’re not affected by network speeds after installation, which makes the bundle size less critical.

💡 Because of a misconfiguration from a few Angular versions ago, the bundle size that we reported in this tweet was overly bloated. We corrected it, but Lit still came out ahead in terms of size and rendering times.

Build Time

While it might not be important to users of Nx Console, the time it takes to build the project makes a difference to us developers.

Since Lit is just javascript files that don’t require a custom compiler or build tooling, we decided to use esbuild (via @nx/esbuild), which is written in Go and extremely fast. On the other hand, the old UI used the @angular-builders/custom-webpack:browser builder, which uses webpack under the hood.

We went from about 3.5 seconds to less than 2 seconds of build time, which is less of an improvement than we expected. Since we also have to run tailwind over our files, some of that additional esbuild speed seems to be relativized.

Looking Ahead

Rebuilding the UI has paved the road to reduce a lot of the maintenance burden of Nx Console. It will allow us to move even quicker on building new features to provide the best developer experience possible for you.

Specifically, the updated architecture enabled us to build a (still secret and WIP) plugin feature for Nx Console. Just like Nx, there are always going to be things that are unique to your workspace. We want to make it easy for you to extend and modify Nx Console in ways that help you make the most of using it.

So keep your eyes peeled for announcements and let us know via GitHub or Twitter if you have any ideas! We’d love to chat.

One more thing!

Nx Console is a tool by developers for developers and there’s one thing we love — keyboard shortcuts. So of course we had to build some in. In addition to being keyboard-friendly and tabbable, you can do the following:

  • Cmd/Ctrl + Enter to run the generator
  • Cmd/Ctrl + Shift + Enter to start a dry run
  • Cmd/Ctrl + Shift + S to focus the search bar and look for a specific option. Just tab to get back to the form

If the prettier UI and better performance haven’t convinced you, this surely will! 😉


Learn more