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

Commit

Permalink
Merge pull request #27 from hapinessjs/next
Browse files Browse the repository at this point in the history
release(version): v8.1.0
  • Loading branch information
akanass committed Jul 4, 2019
2 parents dc6b794 + a4b09fe commit d67fba3
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 272 deletions.
94 changes: 61 additions & 33 deletions README.md
Expand Up @@ -45,7 +45,7 @@ This is a [Hapiness](https://github.com/hapinessjs/hapiness) Engine for running

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

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

We use `yarn` as package manager.

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

```typescript
import { enableProdMode } from '@angular/core';

import { environment } from './environments/environment';

if (environment.production) {
enableProdMode();
}

export { AppServerModule } from './app/app.server.module';

export { NgUniversalModule } from '@hapiness/ng-universal';
```

Copy `tsconfig.app.json` to `tsconfig.server.json` and change it to build with a `"module"` target of `"commonjs"`.
Expand Down Expand Up @@ -249,20 +259,22 @@ In **build target**, adapt `options.outputPath` to `dist/browser`.
...
}
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/server",
"main": "src/main.server.ts",
"tsConfig": "tsconfig.server.json",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"sourceMap": false
}
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/server",
"main": "src/main.server.ts",
"tsConfig": "tsconfig.server.json"
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
}
}
...
Expand Down Expand Up @@ -313,23 +325,17 @@ At the ROOT level of your project (where package.json / etc are), created a file
### server.ts (root project level):

```typescript
// These are important and needed before anything else
import 'reflect-metadata';
// This is important and needed before anything else
import 'zone.js/dist/zone-node';

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

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

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');
const { AppServerModuleNgFactory, LAZY_MODULE_MAP, NgUniversalModule} = require('./dist/server/main');

// Create our Hapiness application
@Module({
Expand Down Expand Up @@ -441,15 +447,13 @@ module.exports = {
optimization: {
minimize: false
},
externals: [
/(node_modules)/
],
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: "commonjs"
},
module: {
noParse: /polyfills-.*\.js/,
rules: [
{ test: /\.ts$/, loader: 'ts-loader' },
{
Expand All @@ -469,12 +473,7 @@ module.exports = {
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
/(.+)?hapiness(\\|\/)core(.+)?/,
path.join(__dirname, 'src'),
{}
),
new webpack.ContextReplacementPlugin(
/(.+)?hapiness(\\|\/)ng-universal(.+)?/,
/(.+)?hapiness(\\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)
Expand All @@ -485,6 +484,32 @@ module.exports = {
};
```

You can add this config if you want to use `@hapiness/config` to have server config in `./config/default.yml` instead of static data:

```javascript
externals: [
{
// This is the only module you have to install with npm in your final packaging
// npm i config
config: {
commonjs: 'config',
root: 'config'
}
}
]
```

And replace the `bootstrap` in *./server.ts*

```typescript
import { Config } from '@hapiness/config';

// Boostrap Hapiness application
Hapiness.bootstrap(HapinessApplication, [
HttpServer.setConfig<HttpServerConfig>(Config.get('server'))
]);
```

Now, you can build your server file:

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

## Change History
* v8.1.0 (2019-07-04)
* `Angular v8.1.0+`
* Documentation to allow dynamic import syntax directly to load lazy loaded chunks
* v8.0.0 (2019-05-31)
* `Angular v8.0.0+`
* Migrate server to `Hapiness` v2 based on [Fastify](https://www.fastify.io/)
Expand Down
50 changes: 25 additions & 25 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@hapiness/ng-universal",
"version": "8.0.0",
"version": "8.1.0",
"description": "This is a Hapiness Engine for running Angular Apps on the server for server side rendering.",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -75,42 +75,42 @@
"cookie": "^0.4.0"
},
"devDependencies": {
"@angular/animations": "^8.0.0",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/compiler-cli": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/animations": "^8.1.0",
"@angular/common": "^8.1.0",
"@angular/compiler": "^8.1.0",
"@angular/compiler-cli": "^8.1.0",
"@angular/core": "^8.1.0",
"@angular/http": "^8.0.0-beta.10",
"@angular/platform-browser": "^8.0.0",
"@angular/platform-browser-dynamic": "^8.0.0",
"@angular/platform-server": "^8.0.0",
"@angular/platform-browser": "^8.1.0",
"@angular/platform-browser-dynamic": "^8.1.0",
"@angular/platform-server": "^8.1.0",
"@hapiness/core": "^2.0.0-alpha",
"@nguniversal/module-map-ngfactory-loader": "^8.0.0-rc.1",
"@types/fs-extra": "^7.0.0",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.2",
"coveralls": "^3.0.3",
"fs-extra": "^8.0.1",
"@nguniversal/module-map-ngfactory-loader": "^8.1.0",
"@types/fs-extra": "^8.0.0",
"@types/jest": "^24.0.15",
"@types/node": "^12.0.12",
"coveralls": "^3.0.4",
"fs-extra": "^8.1.0",
"jest": "^24.8.0",
"rimraf": "^2.6.3",
"rxjs": "^6.5.2",
"ts-jest": "^24.0.2",
"ts-node": "^8.2.0",
"tslint": "^5.17.0",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"typescript": "~3.4.5",
"zone.js": "^0.9.1"
},
"peerDependencies": {
"@angular/compiler": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/platform-server": "^8.0.0",
"@angular/compiler": "^8.1.0",
"@angular/core": "^8.1.0",
"@angular/platform-server": "^8.1.0",
"@hapiness/core": "^2.0.0-alpha",
"@hapiness/ng-universal-transfer-http": "^10.0.0",
"@nguniversal/module-map-ngfactory-loader": "^8.0.0-rc.1",
"@hapiness/ng-universal-transfer-http": "^10.1.0",
"@nguniversal/module-map-ngfactory-loader": "^8.1.0",
"rxjs": "^6.5.2",
"ts-loader": "^6.0.1",
"webpack": "^4.32.2",
"webpack-cli": "^3.3.2"
"ts-loader": "^6.0.4",
"webpack": "^4.35.2",
"webpack-cli": "^3.3.5"
},
"engines": {
"node": ">=7.0.0"
Expand Down

0 comments on commit d67fba3

Please sign in to comment.