You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-18Lines changed: 16 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -31,32 +31,29 @@ Static assets are the files (javascript, css, images) that are generated from a
31
31
32
32
All of the leading application frameworks ([Angular CLI](https://github.com/angular/angular-cli/wiki/stories-application-environments), [Create React App](https://cli.vuejs.org/guide/mode-and-env.html#using-env-variables-in-client-side-code), [Ember CLI](https://ember-cli.com/user-guide/#Environments), [Vue CLI 3](https://cli.vuejs.org/guide/mode-and-env.html#using-env-variables-in-client-side-code)) recommend defining environment _values_ at _compile time_. This practice requires that the static assets are generated for each environment and regenerated for any change to an environment.
33
33
34
-
_Immutable Web Applications_ reference environment _variables_ that are defined on the global scope and that are set to values in the `index.html`that are unique to the deployment:
34
+
_Immutable Web Applications_ reference environment _variables_ that are defined on the global scope and either referenced directly on the `window` object or through an injected service that is a wrapper for the environment variables:
35
35
36
36
```diff
37
-
import { Injectable } from '@angular/core';
38
-
import { HttpClient } from '@angular/common/http';
39
-
40
-
- // remove environment constants that are defined in the codebase or at compile time
41
-
- import { environment } from './environments/environment';
42
-
43
-
@Injectable()
44
-
export class DataService {
45
-
configUrl = ;
37
+
export class UserService {
38
+
webServiceUrl: String;
46
39
47
40
constructor(
48
41
private http: HttpClient
49
-
private
50
-
) { }
42
+
) {
43
+
- // remove any configuration that is hardcoded or included during compilation
44
+
- this.webServiceUrl = 'https://api.myapp.com'
45
+
+ // use globally scoped environment variables that are unique to the deployment
The values for the environment _variables_ are set on an `index.html` that is unique to each environment.
56
+
60
57
#### Static assets must be hosted at locations that are unique and _independent of the web application environment(s)_.
61
58
62
59
Static assets that do not contain anything environment-specific can be built once, published to a unique location, and then used in multiple environments of the web application.
@@ -96,7 +93,7 @@ Static assets that do not contain anything environment-specific and are hosted
96
93
```html
97
94
<script>
98
95
env = {
99
-
API:'https://api.myapp.com'
96
+
API:'https://api.myapp.com',
100
97
GA:'UA-126263119-1'
101
98
}
102
99
</script>
@@ -127,7 +124,8 @@ The `index.html` of most single-page web applications is typically a small docum
0 commit comments