Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit a4b09fe

Browse files
committed
release(version): v8.1.0
1 parent d2b9d70 commit a4b09fe

File tree

3 files changed

+346
-272
lines changed

3 files changed

+346
-272
lines changed

README.md

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ This is a [Hapiness](https://github.com/hapinessjs/hapiness) Engine for running
4545

4646
This story will show you how to set up Universal bundling for an existing `@angular/cli`.
4747

48-
We support actually `@angular` `@8.0.0` and next so you must upgrade all packages inside your project.
48+
We support actually `@angular` `@8.1.0` and next so you must upgrade all packages inside your project.
4949

5050
We use `yarn` as package manager.
5151

@@ -193,7 +193,17 @@ Create a main file for your Universal bundle. This file only needs to export you
193193
### src/main.server.ts:
194194

195195
```typescript
196+
import { enableProdMode } from '@angular/core';
197+
198+
import { environment } from './environments/environment';
199+
200+
if (environment.production) {
201+
enableProdMode();
202+
}
203+
196204
export { AppServerModule } from './app/app.server.module';
205+
206+
export { NgUniversalModule } from '@hapiness/ng-universal';
197207
```
198208

199209
Copy `tsconfig.app.json` to `tsconfig.server.json` and change it to build with a `"module"` target of `"commonjs"`.
@@ -249,20 +259,22 @@ In **build target**, adapt `options.outputPath` to `dist/browser`.
249259
...
250260
}
251261
"server": {
252-
"builder": "@angular-devkit/build-angular:server",
253-
"options": {
254-
"outputPath": "dist/server",
255-
"main": "src/main.server.ts",
256-
"tsConfig": "tsconfig.server.json",
257-
"fileReplacements": [
258-
{
259-
"replace": "src/environments/environment.ts",
260-
"with": "src/environments/environment.prod.ts"
261-
}
262-
],
263-
"optimization": true,
264-
"sourceMap": false
265-
}
262+
"builder": "@angular-devkit/build-angular:server",
263+
"options": {
264+
"outputPath": "dist/server",
265+
"main": "src/main.server.ts",
266+
"tsConfig": "tsconfig.server.json"
267+
},
268+
"configurations": {
269+
"production": {
270+
"fileReplacements": [
271+
{
272+
"replace": "src/environments/environment.ts",
273+
"with": "src/environments/environment.prod.ts"
274+
}
275+
]
276+
}
277+
}
266278
}
267279
}
268280
...
@@ -313,23 +325,17 @@ At the ROOT level of your project (where package.json / etc are), created a file
313325
### server.ts (root project level):
314326

315327
```typescript
316-
// These are important and needed before anything else
317-
import 'reflect-metadata';
328+
// This is important and needed before anything else
318329
import 'zone.js/dist/zone-node';
319330

320-
import { enableProdMode } from '@angular/core';
321331
import { Hapiness, Module } from '@hapiness/core';
322332
import { HttpServer, HttpServerConfig } from '@hapiness/core/httpserver';
323-
import { NgUniversalModule } from '@hapiness/ng-universal';
324333
import { join } from 'path';
325334

326335
const BROWSER_FOLDER = join(process.cwd(), 'dist', 'browser');
327336

328-
// Faster server renders w/ Prod mode (dev mode never needed)
329-
enableProdMode();
330-
331337
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
332-
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');
338+
const { AppServerModuleNgFactory, LAZY_MODULE_MAP, NgUniversalModule} = require('./dist/server/main');
333339

334340
// Create our Hapiness application
335341
@Module({
@@ -441,15 +447,13 @@ module.exports = {
441447
optimization: {
442448
minimize: false
443449
},
444-
externals: [
445-
/(node_modules)/
446-
],
447450
output: {
448451
path: path.join(__dirname, 'dist'),
449452
filename: '[name].js',
450453
libraryTarget: "commonjs"
451454
},
452455
module: {
456+
noParse: /polyfills-.*\.js/,
453457
rules: [
454458
{ test: /\.ts$/, loader: 'ts-loader' },
455459
{
@@ -469,12 +473,7 @@ module.exports = {
469473
{} // a map of your routes
470474
),
471475
new webpack.ContextReplacementPlugin(
472-
/(.+)?hapiness(\\|\/)core(.+)?/,
473-
path.join(__dirname, 'src'),
474-
{}
475-
),
476-
new webpack.ContextReplacementPlugin(
477-
/(.+)?hapiness(\\|\/)ng-universal(.+)?/,
476+
/(.+)?hapiness(\\|\/)(.+)?/,
478477
path.join(__dirname, 'src'),
479478
{}
480479
)
@@ -485,6 +484,32 @@ module.exports = {
485484
};
486485
```
487486

487+
You can add this config if you want to use `@hapiness/config` to have server config in `./config/default.yml` instead of static data:
488+
489+
```javascript
490+
externals: [
491+
{
492+
// This is the only module you have to install with npm in your final packaging
493+
// npm i config
494+
config: {
495+
commonjs: 'config',
496+
root: 'config'
497+
}
498+
}
499+
]
500+
```
501+
502+
And replace the `bootstrap` in *./server.ts*
503+
504+
```typescript
505+
import { Config } from '@hapiness/config';
506+
507+
// Boostrap Hapiness application
508+
Hapiness.bootstrap(HapinessApplication, [
509+
HttpServer.setConfig<HttpServerConfig>(Config.get('server'))
510+
]);
511+
```
512+
488513
Now, you can build your server file:
489514

490515
```bash
@@ -518,7 +543,7 @@ Now lets create a few handy scripts to help us do all of this in the future.
518543
"serve:dynamic": "node dist/server.js",
519544
520545
// Helpers for the above scripts
521-
"build:client-and-server-bundles": "ng build --prod && ng run your-project-name:server",
546+
"build:client-and-server-bundles": "ng build --prod && ng run your-project-name:server:production",
522547
"webpack:server": "webpack --config webpack.server.config.js --progress --colors"
523548
}
524549
```
@@ -552,6 +577,9 @@ To set up your development environment:
552577
[Back to top](#table-of-contents)
553578

554579
## Change History
580+
* v8.1.0 (2019-07-04)
581+
* `Angular v8.1.0+`
582+
* Documentation to allow dynamic import syntax directly to load lazy loaded chunks
555583
* v8.0.0 (2019-05-31)
556584
* `Angular v8.0.0+`
557585
* Migrate server to `Hapiness` v2 based on [Fastify](https://www.fastify.io/)

package.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hapiness/ng-universal",
3-
"version": "8.0.0",
3+
"version": "8.1.0",
44
"description": "This is a Hapiness Engine for running Angular Apps on the server for server side rendering.",
55
"main": "index.js",
66
"types": "index.d.ts",
@@ -75,42 +75,42 @@
7575
"cookie": "^0.4.0"
7676
},
7777
"devDependencies": {
78-
"@angular/animations": "^8.0.0",
79-
"@angular/common": "^8.0.0",
80-
"@angular/compiler": "^8.0.0",
81-
"@angular/compiler-cli": "^8.0.0",
82-
"@angular/core": "^8.0.0",
78+
"@angular/animations": "^8.1.0",
79+
"@angular/common": "^8.1.0",
80+
"@angular/compiler": "^8.1.0",
81+
"@angular/compiler-cli": "^8.1.0",
82+
"@angular/core": "^8.1.0",
8383
"@angular/http": "^8.0.0-beta.10",
84-
"@angular/platform-browser": "^8.0.0",
85-
"@angular/platform-browser-dynamic": "^8.0.0",
86-
"@angular/platform-server": "^8.0.0",
84+
"@angular/platform-browser": "^8.1.0",
85+
"@angular/platform-browser-dynamic": "^8.1.0",
86+
"@angular/platform-server": "^8.1.0",
8787
"@hapiness/core": "^2.0.0-alpha",
88-
"@nguniversal/module-map-ngfactory-loader": "^8.0.0-rc.1",
89-
"@types/fs-extra": "^7.0.0",
90-
"@types/jest": "^24.0.13",
91-
"@types/node": "^12.0.2",
92-
"coveralls": "^3.0.3",
93-
"fs-extra": "^8.0.1",
88+
"@nguniversal/module-map-ngfactory-loader": "^8.1.0",
89+
"@types/fs-extra": "^8.0.0",
90+
"@types/jest": "^24.0.15",
91+
"@types/node": "^12.0.12",
92+
"coveralls": "^3.0.4",
93+
"fs-extra": "^8.1.0",
9494
"jest": "^24.8.0",
9595
"rimraf": "^2.6.3",
9696
"rxjs": "^6.5.2",
9797
"ts-jest": "^24.0.2",
98-
"ts-node": "^8.2.0",
99-
"tslint": "^5.17.0",
98+
"ts-node": "^8.3.0",
99+
"tslint": "^5.18.0",
100100
"typescript": "~3.4.5",
101101
"zone.js": "^0.9.1"
102102
},
103103
"peerDependencies": {
104-
"@angular/compiler": "^8.0.0",
105-
"@angular/core": "^8.0.0",
106-
"@angular/platform-server": "^8.0.0",
104+
"@angular/compiler": "^8.1.0",
105+
"@angular/core": "^8.1.0",
106+
"@angular/platform-server": "^8.1.0",
107107
"@hapiness/core": "^2.0.0-alpha",
108-
"@hapiness/ng-universal-transfer-http": "^10.0.0",
109-
"@nguniversal/module-map-ngfactory-loader": "^8.0.0-rc.1",
108+
"@hapiness/ng-universal-transfer-http": "^10.1.0",
109+
"@nguniversal/module-map-ngfactory-loader": "^8.1.0",
110110
"rxjs": "^6.5.2",
111-
"ts-loader": "^6.0.1",
112-
"webpack": "^4.32.2",
113-
"webpack-cli": "^3.3.2"
111+
"ts-loader": "^6.0.4",
112+
"webpack": "^4.35.2",
113+
"webpack-cli": "^3.3.5"
114114
},
115115
"engines": {
116116
"node": ">=7.0.0"

0 commit comments

Comments
 (0)