This project was generated with Angular CLI using Nrwl Nx.
Based on:
- mean-starter-tutorial
- workshop-nx-starter
- Allow development of node applications
- nx-fullstack
- angular cli proxy
- Rename
nx-mean-starterto<your-app-name> - Keeping in mind first step, go through Configuration Section.
web app: ng g app web-app --style=scss --unit-test-runner=jest --e2e-test-runner=cypress --routing --prefix=app
web lib:
ng g lib testing --unit-test-runner=none --prefix=appng g lib models --unit-test-runner=jest --no-module --prefix=appng g lib auth --unit-test-runner=jest --directory=feature --prefix=appng g lib router --unit-test-runner=jest --directory=state --prefix=appng g lib users --unit-test-runner=jest --directory=navigation --routing --lazy --parent-module=apps/web-app/src/app/app.module.ts --prefix=app
node: ng g @nrwl/node:application server
node lib: ng g @nrwl/node:library core --unit-test-runner=jest --directory=backend
ng build <app-name> --prod --stats-json
npx webpack-bundle-analyzer dist/apps/<app-name>/stats.json
Install Heroku CLI and login
brew install heroku
heroku login
Create new app on Heroku:
heroku apps:create nx-mean-starter --region eu
Add Heroku remote
heroku git:remote -a nx-mean-starter
Deploy
git push heroku master
- Goto https://mlab.com/home and create new "MongoDB Deployment"
- To to your database -> users https://mlab.com/databases/nx-mean-starter#users
- Add database user
- Remember username and password
- Go to https://dashboard.heroku.com/apps/nx-mean-starter/settings -> Config Vars
- Add
- Key: MONGO_URI
- Value: connection string with username and password
- Add
- Add the same to
.env
-
Create firebase project at https://console.firebase.google.com
-
Go to authentication tab and configure authentication.
-
(optional) Go to database tab and configure cloud firestore.
-
Download firebase-adminsdk private service key
- Navigate to the Service Accounts tab.
- Generate new private key
- Copy content of the key
- Modify (make it one line) and paste it to
.env->FIREBASE_ADMIN
When running production build locally use: node -r dotenv/config dist/apps/server/main.js
- Go to https://console.firebase.google.com -> storage tab
- Activate
- Change rules so that image pipe works (you may change directory name):
service firebase.storage {
match /b/{bucket}/o {
match /test/{allPaths=**} {
allow read;
allow write: if request.auth != null;
}
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
- Create firebase project at https://console.firebase.google.com
- Copy firebase config to
frontendenvironment.
Add your domain (heroku etc.) to the OAuth redirect domains list in the Firebase console -> Auth section -> Sign in method tab.
firebase functions: https://medium.com/mean-fire/nx-nrwl-firebase-functions-98f96f514055
firebase hosting: https://medium.com/mean-fire/express-application-on-firebase-hosting-5baa8914835f
ionic: https://medium.com/mean-fire/nx-nrwl-ionic-1baf3a43db74
- dependencies:
compression body-parser connect-mongo mongoose errorhandler express-session express-validator lodash lusca path passport passport-http-bearer request request-promise-native winston firebase firebase-admin api-query-params - dev dependencies:
@types/compression @types/body-parser @types/mongoose @types/errorhandler @types/express-session @types/lodash @types/lusca @types/passport @types/passport-http-bearer @types/request @types/request-promise-native @types/winston
npm i -g @angular/cli@latest @nrwl/schematics@latest
Create workspace:
create-nx-workspace myworkspacename
// or
create-nx-workspace myworkspacename --yarn
yarn add husky lint-staged -D
Modify .prettierrc:
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100
}Modify tslint.json:
"rules": {
"no-unused-variable": true,
"max-line-length": [true, { "limit": 100, "ignore-pattern": "^import |^export {(.*?)} |http" }],
"ordered-imports": [
true,
{
"named-imports-order": "case-insensitive",
"import-sources-order": "case-insensitive"
}
],
}Modify package.json:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"*.ts": [
"prettier --write",
"tslint --fix",
"git add"
],
"*.{json,css,scss,md}": [
"prettier --write",
"git add"
]
},
"ignore": [
"**/dist/**/*"
]
}ng g jest
yarn add jest-marbles -D
yarn remove jasmine-core jasmine-spec-reporter karma karma-chrome-launcher karma-coverage-istanbul-reporter karma-jasmine karma-jasmine-html-reporter @types/jasminewd2 @types/jasmine
Delete karma.conf.js.
yarn affected:test --all- run tests with report coverage for whole workspaceng test app-name- run tests fo specified app/libng test app-name --watch- run tests listening for changes.
Omitting app-name will result in running command for the default app.
Create apps/web-app/proxy.conf.json:
{
"/api": {
"target": "http://localhost:3333",
"secure": false
}
}In angular.json in web-app section add proxyConfig:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "web-app:build",
"proxyConfig": "apps/web-app/proxy.conf.json"
},ng add @angular/pwa --project <project-name>
When changing theme, also change:
manifest.webmanifestindex.html-><meta name="theme-color" content="{{color}}" />
When adding new script tag dependencies include them inside ngsw-config.json.
To generate icons
- Create folder with icon inside called
icon.png - Run
npx ngx-pwa-icons - Copy generated icons to respective directories
Setup environment following this.
ng add @angular/material
yarn add bootstrap
yarn add sass-rem -D
In apps/web-app/src/main.ts add:
import 'hammerjs';In AppModule add to imports:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';In apps/web-app/src/index.html:
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" />
</head>
...
<body class="mat-typography"></body>At the root directory, delete mentions of the library in following files:
angular.jsonnx.jsontsconfig.json