angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.77k stars 11.98k forks source link

Add an option to `ng new` to create a zoneless project. #28370

Closed JeanMeche closed 3 weeks ago

JeanMeche commented 2 months ago

Command

new

Description

It'd be great if we could scafold a zoneless project directly from ng new.

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

dgp1130 commented 2 months ago

@JeanMeche What exactly does this entail at this point? Is it just removing import 'zone.js'; from polyfills.ts / package.json and adding provideExperimentalZonelessChangeDetection? Should we wait for that API to be stabilized / in dev preview? Is there anything else we'd need to configure?

@atscott is this the right time to be thinking about supporting Zoneless in ng new?

JeanMeche commented 2 months ago

Yes, that would be it (and not include provideZoneChangeDetection({ eventCoalescing: true })).

dgp1130 commented 2 months ago

Had a quick conversation within Tooling and with @atscott. We're on board with the idea of something like ng new --zoneless, the question is mainly about timing.

We want to avoid generating experimental code like provideExperimentalZonelessChangeDetection with standard (non-experimental) CLI arguments. Also the SSR story for Zoneless isn't quite figured out yet, so ng new --zoneless --ssr is not likely to generate a usable project.

We think it's probably best to wait until Zoneless is in a stable enough state to start recommending projects consider it. ng new support isn't blocking anything in that effort and adopting Zoneless is relatively straightforward (in the sense of the operations the CLI can do for you).

In the meantime, we're open to an ng new --experimental-zoneless flag since that would at least be clear about the experimental status if anyone wants to contribute it. Otherwise I expect we'll come back to this once Angular is ready to push Zoneless more strongly for new projects.

aparzi commented 1 month ago

Hi @dgp1130, I have implemented new option for create zoneless project, but when I test the build in local I run command npm i -D ${path_cli_project}/dist/*.tgz I receive this error:

While resolving: @angular/pwa@0.0.0 npm ERR! Found: @angular/cli@0.0.0 npm ERR! node_modules/@angular/cli npm ERR! dev @angular/cli@"file:../angular-cli/dist/_angular_cli.tgz" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peerOptional @angular/cli@"^19.0.0-next.0" from @angular/pwa@0.0.0 npm ERR! node_modules/@angular/pwa npm ERR! dev @angular/pwa@"file:../angular-cli/dist/_angular_pwa.tgz" from the root project

Why?

Thanks

aparzi commented 1 month ago

I added experimental-zoneless in schema.json in ng-new folder but i get message Error: Unknown argument: experimental-zoneless

When i run ng new project-name --experimental-zoneless