Skip to content

Commit 7c76162

Browse files
committed
Added improved support for development env (server side + client side), Readme updated
1 parent da4f4b0 commit 7c76162

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ After cloning, run `npm install`
2424

2525
## Development server
2626

27-
Run `ng serve`
27+
Run `npm run start` to spin the front end Angular
28+
Run `npm run dev` to start the Node server in development mode
2829

29-
Navigate to `http://localhost:4200/`.
30+
Navigate to `http://localhost:3015/`.
31+
32+
You can now seamlessly see your changes reflect in realtime everytime you save your file.
3033

3134
## Code scaffolding
3235

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",
7-
"start": "ng serve",
7+
"start": "ng serve --aot",
88
"build": "ng build --prod",
99
"tsc": "tsc -w",
1010
"nodemon": "nodemon dist/server/server.js",
1111
"dev": "tsc && npm run post-dev",
12-
"post-dev": "concurrently \"tsc -w\" \"nodemon dist/server/server.js\"",
12+
"post-dev": "concurrently \"tsc -w\" \"NODE_ENV=dev nodemon dist/server.js\"",
1313
"prod": "ng build --prod --aot && tsc && npm run post-prod",
1414
"post-prod": "node dist/server/server.js",
1515
"test": "ng build --prod --aot && tsc",

server.ts

+22-20
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,29 @@ const app = express();
1919
const PORT = process.env.PORT || 3015;
2020
const DIST_FOLDER = join(process.cwd(), 'dist');
2121

22-
// Our index.html we'll use as our template
23-
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
24-
25-
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
26-
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main.js');
27-
28-
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
29-
30-
app.engine('html', (_, options, callback) => {
31-
renderModuleFactory(AppServerModuleNgFactory, {
32-
// Our index.html
33-
document: template,
34-
url: options.req.url,
35-
// DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
36-
extraProviders: [
37-
provideModuleMap(LAZY_MODULE_MAP)
38-
]
39-
}).then(html => {
40-
callback(null, html);
22+
if (process.env.NODE_ENV !== 'dev') {
23+
// Our index.html we'll use as our template
24+
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
25+
26+
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
27+
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main.js');
28+
29+
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
30+
31+
app.engine('html', (_, options, callback) => {
32+
renderModuleFactory(AppServerModuleNgFactory, {
33+
// Our index.html
34+
document: template,
35+
url: options.req.url,
36+
// DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
37+
extraProviders: [
38+
provideModuleMap(LAZY_MODULE_MAP)
39+
]
40+
}).then(html => {
41+
callback(null, html);
42+
});
4143
});
42-
});
44+
}
4345

4446
app.use('/api', api);
4547
app.set('view engine', 'html');

0 commit comments

Comments
 (0)