Skip to content

Workspace - Use angular library without bundling #19018

Closed
@prabh-62

Description

@prabh-62

🚀 Feature request

Angular CLI shouldn't require angular library to be built before being consumed in an angular application residing in the same angular workspace.

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Description

Current Angular CLI (v11.0.0-next.6) requires that the angular library be built before it can be consumed in angular applications.

Steps

  • > npx @angular/cli@11.0.0-next.6 new agency-apps --strict true --createApplication false
  • > cd agency-apps
  • > yarn ng generate library @agency/auth
  • > yarn ng generate application admin-console --routing true --style css
  • Update projects/admin-console/src/app/app.component.ts
import { Component } from '@angular/core';
import { AuthService } from '@agency/auth';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  title = 'admin-console';

  constructor(private readonly AuthService: AuthService) {
    console.log(this.AuthService);
  }
}
  • > yarn start --project admin-console. Angular CLI will error out since we didn't build library @agency/auth before starting admin-console application

ng_lib_build

Describe the solution you'd like

Angular workspaces should not require developers to build libraries before consuming them. Due to this behaviour, it is required that we, developers put a postinstall script which builds all angular libraries so CI doesn't error out while building angular applications. Ideally, angular libraries in workspace should work just like project references in dotnet ecosystem.

Describe alternatives you've considered

  • Update tsconfig.json from this code snippet
  "compilerOptions": {
    ...
    "paths": {
      "@agency/auth": [
        "dist/agency/auth/agency-auth",
        "dist/agency/auth"
      ]
    }
  }

to

"compilerOptions": {
    ...
    "paths": {
      "@agency/auth": ["projects/agency/auth/src/public-api.ts"]
    }
  }
  • > yarn start --project admin-console

ng_lib_reference

This approach doesn't require angular libraries to be built before consuming them in apps

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions