Skip to content

Commit

Permalink
feat: switch to full standalone mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaliske committed Jul 19, 2023
1 parent a0522e5 commit 040d6f5
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 71 deletions.
6 changes: 4 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
"outputHashing": "all",
"statsJson": true
},
"development": {
"buildOptimizer": false,
Expand Down Expand Up @@ -146,7 +147,8 @@
"prerender": {
"builder": "@nguniversal/builders:prerender",
"options": {
"routes": ["/", "/home", "/about", "/skills", "/work", "/contact", "/legal-notice"]
"routes": ["/", "/home", "/skills", "/work", "/contact", "/legal-notice"],
"guessRoutes": false
},
"defaultConfiguration": "production",
"configurations": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"changelog": "standard-changelog -r 1"
},
"private": true,
"sideEffects": false,
"prettier": "@pascaliske/prettier-config",
"dependencies": {
"@angular/animations": "^16.1.1",
Expand Down
6 changes: 3 additions & 3 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { ngExpressEngine } from '@nguniversal/express-engine'
import * as express from 'express'
import { existsSync } from 'fs'
import { join } from 'path'
import { AppServerModule } from './src/main.server'
import bootstrap from './src/main.server'

export * from './src/main.server'
export default bootstrap

export function app(): express.Express {
const server: express.Express = express()
Expand All @@ -16,7 +16,7 @@ export function app(): express.Express {
: 'index'

// prepare view engine
server.engine('html', ngExpressEngine({ bootstrap: AppServerModule }))
server.engine('html', ngExpressEngine({ bootstrap }))
server.set('view engine', 'html')
server.set('views', distFolder)

Expand Down
13 changes: 13 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { Component, OnInit, DestroyRef, inject } from '@angular/core'
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'
import { RouterOutlet } from '@angular/router'
import { NgProgressModule } from 'ngx-progressbar'
import { ThemeService } from 'shared/theme/theme.service'
import { NavigationComponent } from 'components/navigation/navigation.component'
import { FooterComponent } from 'components/footer/footer.component'
import { TriangleComponent } from 'components/triangle/triangle.component'
import { animations } from './app.animations'

@Component({
standalone: true,
selector: 'cmp-root',
templateUrl: './app.component.html',
styleUrls: [],
imports: [
RouterOutlet,
NgProgressModule,
NavigationComponent,
FooterComponent,
TriangleComponent,
],
animations,
})
export class AppComponent implements OnInit {
Expand Down
7 changes: 7 additions & 0 deletions src/app/app.config.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ApplicationConfig, mergeApplicationConfig } from '@angular/core'
import { provideServerRendering } from '@angular/platform-server'
import { appConfig } from './app.config'

export const serverConfig: ApplicationConfig = mergeApplicationConfig(appConfig, {
providers: [provideServerRendering()],
})
28 changes: 28 additions & 0 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { importProvidersFrom, ApplicationConfig, ValueProvider, APP_ID } from '@angular/core'
import { BrowserModule, provideClientHydration } from '@angular/platform-browser'
import { provideAnimations } from '@angular/platform-browser/animations'
import { provideRouter } from '@angular/router'
import { NgProgressModule } from 'ngx-progressbar'
import { NgProgressHttpModule } from 'ngx-progressbar/http'
import { NgProgressRouterModule } from 'ngx-progressbar/router'
import { features, routes } from './app.routing'

export const provideAppId: () => ValueProvider = (): ValueProvider => ({
provide: APP_ID,
useValue: 'pascaliske-dev',
})

export const appConfig: ApplicationConfig = {
providers: [
importProvidersFrom(
BrowserModule,
NgProgressModule.withConfig({ color: '#ff6666', fixed: true }),
NgProgressHttpModule,
NgProgressRouterModule,
),
provideClientHydration(),
provideAnimations(),
provideRouter(routes, ...features),
provideAppId(),
],
}
29 changes: 0 additions & 29 deletions src/app/app.module.ts

This file was deleted.

26 changes: 11 additions & 15 deletions src/app/app-routing.module.ts → src/app/app.routing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { NgModule } from '@angular/core'
import { RouterModule, Routes } from '@angular/router'
import type { RouterFeatures, Routes } from '@angular/router'
import { withEnabledBlockingInitialNavigation, withInMemoryScrolling } from '@angular/router'
import { RedirectGuardFn } from 'shared/redirect/redirect.guard'

export const features: RouterFeatures[] = [
withEnabledBlockingInitialNavigation(),
withInMemoryScrolling({
anchorScrolling: 'enabled',
scrollPositionRestoration: 'enabled',
// scrollOffset: [0, 100],
}),
]

export const routes: Routes = [
{
path: '',
Expand Down Expand Up @@ -58,16 +67,3 @@ export const routes: Routes = [
redirectTo: 'home',
},
]

@NgModule({
imports: [
RouterModule.forRoot(routes, {
anchorScrolling: 'enabled',
scrollPositionRestoration: 'enabled',
scrollOffset: [0, 100],
initialNavigation: 'enabledBlocking',
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
10 changes: 0 additions & 10 deletions src/app/app.server.module.ts

This file was deleted.

11 changes: 10 additions & 1 deletion src/main.server.ts
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
export { AppServerModule } from './app/app.server.module'
import { ApplicationRef } from '@angular/core'
import { bootstrapApplication } from '@angular/platform-browser'
import { AppComponent } from './app/app.component'
import { serverConfig } from './app/app.config.server'

export const bootstrap: () => Promise<ApplicationRef> = () => {
return bootstrapApplication(AppComponent, serverConfig)
}

export default bootstrap
17 changes: 6 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { enableProdMode } from '@angular/core'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { AppModule } from './app/app.module'
import { environment } from './environments/environment'
import { bootstrapApplication } from '@angular/platform-browser'
import { AppComponent } from './app/app.component'
import { appConfig } from './app/app.config'

if (environment.production) {
enableProdMode()
}

platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.error(err))
bootstrapApplication(AppComponent, appConfig).catch(err => {
console.error(err)
})

0 comments on commit 040d6f5

Please sign in to comment.