Skip to content

Commit ed89648

Browse files
committed
feat: add deploy to Firebase Hosting and custom 404 page
1 parent 93da84b commit ed89648

File tree

10 files changed

+2834
-130
lines changed

10 files changed

+2834
-130
lines changed

.firebaserc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"targets": {
3+
"angular-cli-static": {
4+
"hosting": {
5+
"static-html": [
6+
"angular-cli-static"
7+
]
8+
}
9+
}
10+
}
11+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ npm-debug.log
4040
yarn-error.log
4141
testem.log
4242
/typings
43+
*.log
44+
*.cache
4345

4446
# System Files
4547
.DS_Store

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ The app will automatically reload if you change any of the source files.
1616

1717
The build artifacts will be stored in the `dist/` directory.
1818

19+
## Deploy
20+
21+
1. Change [.firebaserc](.firebaserc) to point to your Firebase Hosting project
22+
1. Ensure that you are logged in to Firebase: `npm run login`
23+
1. Run `npm run deploy`
24+
1925
## Key Configuration Steps
2026

2127
1. Create a workspace without an app:
@@ -29,10 +35,36 @@ ng g app --style=scss --minimal=true --routing=false --skip-tests=true static-ht
2935
1. Comment out `zone.js` import in [polyfills.ts](polyfills.ts)
3036
1. In [angular.json](angular.json) clear out `"fileReplacements": []`
3137
1. Remove `app/`, `environments/`
32-
1. Remove most of the Angular dependencies from [package.json](package.json)'s `dependencies`
33-
other than `@angular/core`, `@angular/compiler`, and `rxjs`
34-
1. Remove `codelyzer` and `@angular/language-service` from [package.json](package.json)'s `devDependencies`
38+
1. Remove the following Angular dependencies from [package.json](package.json)'s `dependencies`:
39+
- `@angular/animations`
40+
- `@angular/forms`
41+
1. Remove the following dependencies from [package.json](package.json)'s `devDependencies`:
42+
- `codelyzer`
43+
- `@angular/language-service`
3544
1. Remove `codelyzer` from `rulesDirectory` and remove all of the Codelyzer rules from
3645
the workspace [tslint.json](tslint.json)
3746
1. Remove `directive-selector` and `component-selector` rules
3847
from your app's [tslint.json](projects/static-html/tslint.json)
48+
1. Enable Deployment to Firebase
49+
```shell script
50+
ng add @angular/fire
51+
```
52+
1. Update your [firebase.json](firebase.json) to work with a static site rather than a SPA
53+
```json
54+
"rewrites": [
55+
{
56+
"source": "/",
57+
"destination": "/index.html"
58+
}
59+
]
60+
```
61+
1. Add a [404.html](projects/static-html/src/404.html) and [404.css](projects/static-html/src/404.css)
62+
1. Update your project's assets list in [angular.json](angular.json) to include the new files
63+
```json
64+
"assets": [
65+
"projects/static-html/src/favicon.ico",
66+
"projects/static-html/src/404.html",
67+
"projects/static-html/src/404.css",
68+
"projects/static-html/src/assets"
69+
],
70+
```

angular.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"aot": true,
2626
"assets": [
2727
"projects/static-html/src/favicon.ico",
28+
"projects/static-html/src/404.html",
29+
"projects/static-html/src/404.css",
2830
"projects/static-html/src/assets"
2931
],
3032
"styles": [
@@ -85,9 +87,14 @@
8587
"**/node_modules/**"
8688
]
8789
}
90+
},
91+
"deploy": {
92+
"builder": "@angular/fire:deploy",
93+
"options": {}
8894
}
8995
}
90-
}},
96+
}
97+
},
9198
"cli": {
9299
"analytics": "fc7225a9-dc2b-4b2a-a9a7-ad4d6246ca26"
93100
},

firebase.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"hosting": [
3+
{
4+
"target": "static-html",
5+
"public": "dist/static-html",
6+
"ignore": [
7+
"firebase.json",
8+
"**/.*",
9+
"**/node_modules/**"
10+
],
11+
"rewrites": [
12+
{
13+
"source": "/",
14+
"destination": "/index.html"
15+
}
16+
]
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)