diff --git a/lerna.json b/lerna.json new file mode 100644 index 0000000000..d6707ca0cd --- /dev/null +++ b/lerna.json @@ -0,0 +1,6 @@ +{ + "packages": [ + "packages/*" + ], + "version": "0.0.0" +} diff --git a/package.json b/package.json index 6820d788d7..5f9b872556 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "private": true, + "description": "Ionic mono-repo root package.json, used mainly to execute build scripts. This package is not published to npm.", "scripts": { "build": "node .scripts/build.js", "release.dev": "node .scripts/release-dev.js", @@ -13,7 +14,9 @@ "execa": "^0.10.0", "fs-extra": "^7.0.0", "inquirer": "^6.0.0", + "lerna": "^3.16.2", "listr": "^0.14.0", + "rimraf": "^2.6.3", "semver": "^5.5.0", "turbocolor": "^2.4.1" }, diff --git a/packages/angular-server/.npmrc b/packages/angular-server/.npmrc new file mode 100644 index 0000000000..43c97e719a --- /dev/null +++ b/packages/angular-server/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/angular-server/package.json b/packages/angular-server/package.json new file mode 100644 index 0000000000..430996435e --- /dev/null +++ b/packages/angular-server/package.json @@ -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" + } +} diff --git a/packages/angular-server/readme.md b/packages/angular-server/readme.md new file mode 100644 index 0000000000..1fd4b8b130 --- /dev/null +++ b/packages/angular-server/readme.md @@ -0,0 +1,3 @@ +# @ionic/angular-server + +Angular SSR Module for Ionic components. diff --git a/packages/angular-server/src/ionic-server-module.ts b/packages/angular-server/src/ionic-server-module.ts new file mode 100644 index 0000000000..d24a6cfccd --- /dev/null +++ b/packages/angular-server/src/ionic-server-module.ts @@ -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; + 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; + for (let i = 0; i < ionPages.length; i++) { + ionPages[i].classList.remove('ion-page-invisible'); + } + } + }); + }; +} diff --git a/packages/angular-server/tsconfig.json b/packages/angular-server/tsconfig.json new file mode 100644 index 0000000000..e5ab7763da --- /dev/null +++ b/packages/angular-server/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..ae1ecab3c7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,46 @@ +{ + "compilerOptions": { + "alwaysStrict": true, + "strict": true, + "allowSyntheticDefaultImports": true, + "allowUnreachableCode": false, + "declaration": true, + "experimentalDecorators": true, + "forceConsistentCasingInFileNames": true, + "lib": [ + "dom", + "es2017" + ], + "module": "es2015", + "moduleResolution": "node", + "noImplicitAny": true, + "noImplicitReturns": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "pretty": true, + "removeComments": false, + "strictPropertyInitialization": false, + "target": "es2017", + "baseUrl": ".", + "paths": { + "@ionic/core/hydrate": [ + "./core/hydrate" + ], + "@ionic/core": [ + "./core" + ], + "@ionic/angular": [ + "./angular" + ], + "@ionic/angular-server": [ + "./packages/angular-server" + ], + "@ionic/react": [ + "./react" + ], + "@ionic/vue": [ + "./vue" + ] + } + } +}