Skip to content

Commit 4579377

Browse files
authored
build: fix error when dev app is deployed (#23864)
The `index.html` of the dev app assumes that the `DEV_APP_VARIABLES` global variable will always be present, but that's not the case when it is deployed. This causes an error which prevents the Google Maps script from loading. These changes add a null check, as well as some docs about the `variables.json`.
1 parent a0597ec commit 4579377

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

DEV_ENVIRONMENT.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Developer guide: getting your environment set up
2-
32
1. Make sure you have both `node` and `yarn` installed.
43
We recommend using `nvm` to manage your node versions.
54
2. angular/components uses Bazel which requires certain Bash and UNIX tools.
@@ -19,7 +18,6 @@ To bring up a local server, run `yarn dev-app`. This will automatically watch fo
1918
and rebuild. The browser should refresh automatically when changes are made.
2019

2120
### Running tests
22-
2321
To run unit tests, run `yarn test <target>`. The `target` can be either a short name (e.g. `yarn test button`) or an explicit path `yarn test src/cdk/stepper`.
2422
To run the e2e tests, run `yarn e2e`.
2523
To run lint, run `yarn lint`.
@@ -67,7 +65,6 @@ at the file under `tools/public_api_guard/<target>.d.ts`.
6765

6866

6967
### Disabling Git hooks
70-
7168
If your development workflow does not intend the commit message validation to run automatically
7269
when commits are being created, or if you do not want to run the formatter upon `git commit`, you
7370
can disable any installed Git hooks by setting `HUSKY=0` in your shell environment. e.g.
@@ -78,4 +75,11 @@ export HUSKY=0
7875

7976
# .bashrc
8077
export HUSKY=0
81-
```
78+
```
79+
80+
### Injecting variables into the dev app
81+
Variables can be injected into the dev app by creating the `src/dev-app/variables.json` file.
82+
They'll be made available under the `window.DEV_APP_VARIABLES` object. The file isn't checked into
83+
Git and it can be used to pass private configuration like API keys. Variables currently being used:
84+
85+
* `GOOGLE_MAPS_KEY` - Optional key for the Google Maps API.

src/dev-app/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
<script src="https://www.youtube.com/iframe_api"></script>
2424
<script src="https://unpkg.com/@googlemaps/markerclustererplus/dist/index.min.js"></script>
2525
<script>
26-
(function loadGoogleMaps(key) {
26+
(function loadGoogleMaps(variables) {
27+
var key = variables ? variables.GOOGLE_MAPS_KEY : null;
2728
var script = document.createElement('script');
2829
script.src = 'https://maps.googleapis.com/maps/api/js?libraries=visualization' +
2930
(key ? '&key=' + key : '');
3031
document.body.appendChild(script);
31-
})(window.DEV_APP_VARIABLES.GOOGLE_MAPS_KEY);
32+
})(window.DEV_APP_VARIABLES);
3233
</script>
3334
<script src="bundles/dev-app/main.js" type="module"></script>
3435
</body>

0 commit comments

Comments
 (0)