This project is based on angular2-express-starter, TypeScript-Node-Starter and ng-lib-tutorial. It presents steps to reproduce.
npm i -D concurrently nodemon tsconfig-paths tspath @types/express @types/body-parser @types/compression @types/mongoose
- concurrently - required for starting
- nodemon - to listen changes on the server
- tsconfig-paths - to resolve server paths in local development (ts-node)
- tspath - to resolve server paths in production build
npm i express body-parser compression path mongoose normalize.css
- express, body-parser, compression - basic libraries for the server
- mongoose - ODM for MongoDB
- normalize.css - alternative to CSS resets
Procfile
- for heroku, so it knows how to serve applicationproxy.conf.json
- enables referencing server by clientnodemon.json
- contains configuration for localhost serverlibs/*
- sample libs to be used both in Client and Serverserver/*
- basic express server
{
"scripts": {
"start": "concurrently --kill-others \"npm run start:server\" \"npm run start:client\"",
"start:client": "ng serve --aot --progress=false --proxy-config proxy.conf.json",
"start:server": "nodemon",
"build": "npm run build:server && npm run build:client",
"build:client": "ng build --prod",
"build:server": "tsc -p ./server && echo y | tspath -p ./server",
"lint": "npm run lint:client && npm run lint:server",
"lint:client": "ng lint",
"lint:server": "tslint './server/**/*.ts' --fix",
"test:client": "ng test",
"e2e:client": "ng e2e",
"postinstall": "npm run build"
},
"engines": {
"node": "8.10.0",
"npm": "5.6.0"
},
}
{
"apps": [
{
"outDir": "dist/client",
"styles": [
"../node_modules/normalize.css/normalize.css",
"styles.css"
],
}
],
"defaults": {
"styleExt": "scss",
"class": {
"spec": false
},
"component": {
"spec": false
},
"service": {
"spec": false
},
"pipe": {
"spec": false
}
}
}
- Adds path to the library.
- Left Side is a name/alias to be used in the application to import library, it should be of the same name as given library in section "In ng-test-lib folder".
- Right Side is a path to that library.
"compilerOptions": {
"outDir": "./dist",
"baseUrl": ".",
"paths": {
"@my/*": ["libs/*"]
}
}
Remove baseUrl
from compilerOptions
in those files.
Note that absolute routes start now from root folder not src. So angular route to module would look somewhat like that
src/app/weather/weather.module#WeatherModule
In local development ts-node is used along side with tsconfig-paths which allows using paths from tsconfig.json
.
In production build tspath is used to rewrite paths of compiled project. There seams to be limitation as we cannot use path of '*'
. It has to be used with something else like '@my/*'
There many issues on github that collaborate on that problem:
In Angular the CLI is doing most of the work so that paths in tsconfig.json
are enough to make it work.
Those dev dependencies were omitted:
@types/cors @types/uuid @types/jsonwebtoken webdriver-manager
Those regular dependencies were omitted:
uuid cookie-parser jsonwebtoken ts-helpers (whole ngrx)