mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-26 08:13:34 +08:00
chore(angular-server): init angular-server package (#18950)
This commit is contained in:
1
packages/angular-server/.npmrc
Normal file
1
packages/angular-server/.npmrc
Normal file
@ -0,0 +1 @@
|
||||
package-lock=false
|
39
packages/angular-server/package.json
Normal file
39
packages/angular-server/package.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "@ionic/angular-server",
|
||||
"description": "Angular SSR Module for Ionic",
|
||||
"version": "0.0.0",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "ngc -p ./tsconfig.json",
|
||||
"build.prod": "npm run clean && npm run build",
|
||||
"clean": "rm -rf ./dist"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@angular-devkit/core": "~8.0.0",
|
||||
"@angular/common": "~8.0.0",
|
||||
"@angular/core": "~8.0.0",
|
||||
"@angular/platform-server": "~8.0.0",
|
||||
"@ionic/core": "*",
|
||||
"rxjs": ">=6.2.0",
|
||||
"zone.js": ">=0.8.26"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/core": "~8.0.0",
|
||||
"@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/platform-browser": "~8.0.0",
|
||||
"@angular/platform-server": "~8.0.0",
|
||||
"@angular/router": "~8.0.0",
|
||||
"rxjs": "^6.4.0",
|
||||
"tsickle": "^0.34.0",
|
||||
"typescript": "~3.4.3",
|
||||
"zone.js": "~0.9.1"
|
||||
}
|
||||
}
|
3
packages/angular-server/readme.md
Normal file
3
packages/angular-server/readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# @ionic/angular-server
|
||||
|
||||
Angular SSR Module for Ionic components.
|
51
packages/angular-server/src/ionic-server-module.ts
Normal file
51
packages/angular-server/src/ionic-server-module.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { APP_ID, NgModule } from '@angular/core';
|
||||
import { BEFORE_APP_SERIALIZED } from '@angular/platform-server';
|
||||
import { hydrateDocument } from '@ionic/core/hydrate';
|
||||
|
||||
// @dynamic
|
||||
@NgModule({
|
||||
providers: [
|
||||
{
|
||||
provide: BEFORE_APP_SERIALIZED,
|
||||
useFactory: hydrateIonicComponents,
|
||||
multi: true,
|
||||
deps: [DOCUMENT, APP_ID]
|
||||
}
|
||||
]
|
||||
})
|
||||
export class IonicServerModule {}
|
||||
|
||||
// @dynamic
|
||||
export function hydrateIonicComponents(doc: any, appId: any) {
|
||||
return () => {
|
||||
return hydrateDocument(doc, {
|
||||
clientHydrateAnnotations: false
|
||||
})
|
||||
.then(hydrateResults => {
|
||||
hydrateResults.diagnostics.forEach(d => {
|
||||
if (d.type === 'error') {
|
||||
console.error(d.messageText);
|
||||
} else if (d.type === 'debug') {
|
||||
console.debug(d.messageText);
|
||||
} else {
|
||||
console.log(d.messageText);
|
||||
}
|
||||
});
|
||||
|
||||
if (doc.head != null) {
|
||||
const styleElms = doc.head.querySelectorAll('style[data-styles]') as NodeListOf<HTMLStyleElement>;
|
||||
for (let i = 0; i < styleElms.length; i++) {
|
||||
styleElms[i].setAttribute('ng-transition', appId);
|
||||
}
|
||||
}
|
||||
|
||||
if (doc.body != null) {
|
||||
const ionPages = doc.body.querySelectorAll('.ion-page.ion-page-invisible') as NodeListOf<HTMLElement>;
|
||||
for (let i = 0; i < ionPages.length; i++) {
|
||||
ionPages[i].classList.remove('ion-page-invisible');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
18
packages/angular-server/tsconfig.json
Normal file
18
packages/angular-server/tsconfig.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"files": [
|
||||
"src/ionic-server-module.ts"
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"annotateForClosureCompiler": true,
|
||||
"strictMetadataEmit" : true,
|
||||
"flatModuleOutFile": "./index.js",
|
||||
"flatModuleId": "@ionic/angular-server",
|
||||
"skipTemplateCodegen": true,
|
||||
"fullTemplateTypeCheck": false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user