-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build(ng): migrate to standalone app #332
Merged
davidlj95
merged 8 commits into
main
from
stacked/build-ng-migrate-to-standalone-app-conversion
Mar 10, 2024
Merged
build(ng): migrate to standalone app #332
davidlj95
merged 8 commits into
main
from
stacked/build-ng-migrate-to-standalone-app-conversion
Mar 10, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: convert all components, directives and pipes `ng g @angular/core:standalone` (`--mode convert-to-standalone`)
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @davidlj95 and the rest of your teammates on Graphite |
Now, the custom schemas in project module wasn't taking effect Removing it. Also removing from test, given component declares it
davidlj95
force-pushed
the
stacked/build-ng-migrate-to-standalone-app-conversion
branch
from
March 10, 2024 15:48
a700de5
to
fed14c8
Compare
davidlj95
force-pushed
the
stacked/build-ng-migrate-to-standalone-app-conversion
branch
from
March 10, 2024 16:51
01daa3a
to
e0f0385
Compare
davidlj95
force-pushed
the
stacked/build-ng-migrate-to-standalone-app-conversion
branch
from
March 10, 2024 17:00
e0f0385
to
91a70e9
Compare
davidlj95
changed the title
build(ng): migrate to standalone app: conversion
build(ng): migrate to standalone app
Mar 10, 2024
davidlj95
deleted the
stacked/build-ng-migrate-to-standalone-app-conversion
branch
March 10, 2024 17:59
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Migrates the app to standalone
Steps
1. Convert all components, directives and pipes
Ran the command
ng g @angular/core:standalone
(--mode convert-to-standalone
)Then ran all tests. Fixed some errors:
RouterTestingModule
inlogo.component.spec.ts
to make test passswiper.directive.spec.ts
fnmakeComponentWithDirective
makeSut
Git hooks ran the code formatting for us ✅
ng-mocks
discovery: in order to useMockComponent
s APIs, you need to import the component under test inTestBed.configureTestingModule
. Spread operator forMockComponents
is not neededReviewing diff, found out that
NgOptimizedImage
is present inTestBed.configureTestingModule
calls. But it's actually not needed, given the standalone component already imports it.Also, not needed to import / declare the component under test if
MockComponent
APIs are not used. For instance, you can importRoutingTestingModule
to mock Router APIs but don't declare the component under test underimports
/declarations
and create it directly.2. Fix build
https://github.com/davidlj95/chrislb/actions/runs/8222927399/job/22484997305?pr=332
Custom schemas now need to be declared in the standalone component, not in the module where it belongs (given it's now standalone / module-independent). Moving custom schemas declaration to use swiper from project module to images swiper component. Which is way better indeed (custom schemas were only needed for that component). Removing custom schemas from test, given component already declares custom schemas.
3. Remove modules
Ran the command
ng g @angular/core:standalone
(--mode prune-ng-modules
)But nothing could be done automagically. So removing them manually
About module
Moved routes from about routing module to about routes file. To later lazy load that instead (following standalone guide on lazy loading many routes at once). Font Awesome module is already imported by standalone components social / resume. Same for optimized image. Moving
ngx-meta
imports as providers in the routes file. No need to declare components, removing them. Providing the resume service in theResumeComponent
in theproviders
of it.Projects module
Routes were already in a separate file. But whole module was loaded at bootstrap as it's main page, so no need to change routing things. Components, pipes are already standalone. Router APIs are already imported in each component. Projects service is declared where needed: in projects page and project page route (given resolver requires it). Resolver is then provided in the project page route. Assets collections is provided in only component that reqs it: project page. We can then remove project module.
Tests failed though: https://github.com/davidlj95/chrislb/actions/runs/8223441344/job/22486141495?pr=332
Seems that when providing a service through component providers, you need to mock it by calling
TestBed.overrideComponent
APIRouting module
Moved app routing module into
app.routes.ts
. Exports routes array instead of a module. Then, in app module, we useprovideRouter
+ routes from file. Then, the features that were passed toRouterModule.forRoot
are transformed intowithX
APIs.Seems scrolling navigation stop working #333 But already happened before, so moving forward
4. Standalone bootstrap
Ran the command again
ng g @angular/core:standalone
(--mode standalone-bootstrap
)App module disappeared. All configuration was placed in
main.ts
. Moved it toapp.config.ts
, which is the file created by Angular CLI for new Angular v17 projects.HttpClientModule
was transformed intoprovideHttpClient(withInterceptorsFromDi())
. But given we don't use interceptors, removing that feature.Removed
RouterOutlet
from app config providers, given the app component is now standalone and imports it.SSR was broken, given app server module wasn't migrated. And it was trying to import the now removed app module. Generated a new app with
pnpx @angular/cli@17 new --ssr
and observed how that works for standalone apps. Seems a configuration file existsapp.config.server.ts
. Created that file and movied the local JSON fetcher provider there. The file provides the SSR provider + extra providers only for use with SSR. Then,main.server.ts
exportsbootstrap
function instead that takes the server config instead. Thisbootstrap
is eventually used inserver.ts
(as migration in Angular v17 tried to do #330 ).5.
ngx-meta
standalone APIsInstead of modules. In
app.config.ts