Skip to content

Commit 099b2f0

Browse files
committed
fix(angular): fix ssr with runtime option
1 parent 6d3557a commit 099b2f0

16 files changed

Lines changed: 219 additions & 128 deletions

File tree

examples/nx-workspace/apps/ng-app-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@angular/platform-server": "^20.0.5",
3131
"@angular/router": "^20.0.0",
3232
"@angular/ssr": "^20.0.4",
33-
"@ngx-env/builder": "workspace:20.1.0",
33+
"@ngx-env/builder": "workspace:20.1.1",
3434
"express": "^5.1.0",
3535
"rxjs": "~7.8.0",
3636
"tslib": "^2.3.0",
@@ -44,7 +44,7 @@
4444
"@dotenv-run/core": "workspace:^1.3.8",
4545
"@dotenv-run/jest-angular": "workspace:^0.2.1",
4646
"@jest/transform": "^29.7.0",
47-
"@ngx-env/builder": "workspace:^20.1.0",
47+
"@ngx-env/builder": "workspace:^20.1.1",
4848
"@types/express": "^5.0.1",
4949
"@types/jasmine": "~5.1.0",
5050
"@types/node": "^22.12.0",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Include theming for Angular Material with `mat.theme()`.
2+
// This Sass mixin will define CSS variables that are used for styling Angular Material
3+
// components according to the Material 3 design spec.
4+
// Learn more about theming and how to use it for your application's
5+
// custom components at https://material.angular.dev/guide/theming
6+
@use "@angular/material" as mat;
7+
8+
html {
9+
@include mat.theme(
10+
(
11+
color: (
12+
primary: mat.$azure-palette,
13+
tertiary: mat.$blue-palette,
14+
),
15+
typography: Roboto,
16+
density: 0,
17+
)
18+
);
19+
20+
// Default the application to a light color theme. This can be changed to
21+
// `dark` to enable the dark color theme, or to `light dark` to defer to the
22+
// user's system settings.
23+
color-scheme: light;
24+
25+
// Set a default background, font and text colors for the application using
26+
// Angular Material's system-level CSS variables. Learn more about these
27+
// variables at https://material.angular.dev/guide/system-variables
28+
background-color: var(--mat-sys-surface);
29+
color: var(--mat-sys-on-surface);
30+
font: var(--mat-sys-body-medium);
31+
}

packages/angular/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @ngx-env/builder
22

3+
## 20.1.1
4+
5+
### Patch Changes
6+
7+
- Fix SSR with runtime option
8+
39
## 20.1.0
410

511
### Minor Changes

packages/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-env/builder",
3-
"version": "20.1.0",
3+
"version": "20.1.1",
44
"description": "Easily inject environment variables into your Angular applications",
55
"author": "chihab <chihab@gmail.com>",
66
"homepage": "https://github.com/chihab/ngx-env/tree/main/packages/angular",

packages/angular/src/builders/application/index.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import { join } from "path";
1010
import { from, switchMap, tap } from "rxjs";
1111
import { NgxEnvSchema } from "../ngx-env/ngx-env-schema";
1212
import { getEnvironment } from "../utils/get-environment";
13-
import { indexHtml } from "../utils/index-html-build";
13+
import { writeRuntimeFile } from "../utils/write-ngx-env-runtime";
1414
import { getProjectCwd } from "../utils/project";
15+
import { replaceHtmlVars } from "../utils/replace-html-vars";
16+
import { indexHtmlTransformer } from "../utils/index-html-transform";
1517

1618
export const executeWithEnv = (
1719
options: ApplicationBuilderOptions & NgxEnvSchema,
@@ -28,20 +30,30 @@ export const executeWithEnv = (
2830
});
2931
options.define = full;
3032
return fromAsyncIterable<BuilderOutput>(
31-
buildApplication(options, context)
33+
buildApplication(options, context, {
34+
indexHtmlTransformer: async (html) => {
35+
return indexHtmlTransformer(
36+
html,
37+
raw,
38+
false,
39+
dotEnvOptions.runtime
40+
);
41+
},
42+
})
3243
).pipe(
3344
tap(() => {
34-
const outputDir = join(
35-
context.workspaceRoot,
36-
options.outputPath?.toString() ?? `dist/${context.target.project}`
37-
);
38-
indexHtml(
39-
join(outputDir, "browser"),
40-
options.ssr ? join(outputDir, "server") : null,
41-
Array.isArray(options.localize) ? options.localize : [],
42-
raw,
43-
dotEnvOptions.runtime
44-
);
45+
if (dotEnvOptions.runtime) {
46+
const outputDir = join(
47+
context.workspaceRoot,
48+
options.outputPath?.toString() ?? `dist/${context.target.project}`
49+
);
50+
writeRuntimeFile(
51+
join(outputDir, "browser"),
52+
options.ssr ? join(outputDir, "server") : null,
53+
Array.isArray(options.localize) ? options.localize : [],
54+
raw
55+
);
56+
}
4557
})
4658
);
4759
})

packages/angular/src/builders/browser-esbuild/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { join } from "path";
1010
import { from, switchMap, tap } from "rxjs";
1111
import { NgxEnvSchema } from "../ngx-env/ngx-env-schema";
1212
import { getEnvironment } from "../utils/get-environment";
13-
import { indexHtml } from "../utils/index-html-build";
13+
import { indexHtmlTransformerLegacy } from "../utils/index-html-transform-legacy";
1414
import { getProjectCwd } from "../utils/project";
1515

1616
export const executeWithEnv = (
@@ -31,7 +31,7 @@ export const executeWithEnv = (
3131
buildEsbuildBrowser(options, context, undefined)
3232
).pipe(
3333
tap(() => {
34-
indexHtml(
34+
indexHtmlTransformerLegacy(
3535
join(
3636
context.workspaceRoot,
3737
options.outputPath.toString(),

packages/angular/src/builders/browser/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { join } from "path";
77
import { from, switchMap, tap } from "rxjs";
88
import { NgxEnvSchema } from "../ngx-env/ngx-env-schema";
99
import { getEnvironment } from "../utils/get-environment";
10-
import { indexHtml } from "../utils/index-html-build";
10+
import { indexHtmlTransformerLegacy } from "../utils/index-html-transform-legacy";
1111
import { getProjectCwd } from "../utils/project";
1212
import { plugin } from "../utils/webpack-plugin";
1313

@@ -26,7 +26,7 @@ export const executeWithEnv = (
2626
webpackConfiguration,
2727
}).pipe(
2828
tap(() => {
29-
indexHtml(
29+
indexHtmlTransformerLegacy(
3030
join(context.workspaceRoot, options.outputPath.toString()),
3131
null, // no ssr support with browser,
3232
Array.isArray(options.localize) ? options.localize : [],

packages/angular/src/builders/dev-server/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { DotenvRunOptions } from "@dotenv-run/core";
77
import { env } from "@dotenv-run/core";
88
import { catchError, combineLatest, switchMap } from "rxjs";
99
import { getEnvironment } from "../utils/get-environment";
10-
import { indexHtml } from "../utils/index-html-serve";
10+
import { indexHtmlTransformer } from "../utils/index-html-transform";
1111
import { getProjectCwd } from "../utils/project";
1212
import { validateAndPrepareBuildContext } from "../utils/validate-prepare-context";
1313

@@ -35,7 +35,7 @@ export const executeWithEnv = (
3535
});
3636
return executeDevServerBuilder(options, context, {
3737
indexHtmlTransformer: async (content: string) =>
38-
indexHtml(content, raw, dotenvRunOptions.runtime),
38+
indexHtmlTransformer(content, raw, true, dotenvRunOptions.runtime),
3939
});
4040
}),
4141
catchError((e) => {

packages/angular/src/builders/utils/index-html-build.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

packages/angular/src/builders/utils/index-html-serve.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)