-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mobile): re-enable --mobile flag
- Loading branch information
1 parent
2160003
commit 6652ac0
Showing
10 changed files
with
108 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 13 additions & 46 deletions
59
packages/angular-cli/blueprints/mobile/files/__path__/main-app-shell.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,14 @@ | ||
import 'angular2-universal-polyfills'; | ||
import { provide } from '@angular/core'; | ||
import { APP_BASE_HREF } from '@angular/common'; | ||
import { APP_SHELL_BUILD_PROVIDERS } from '@angular/app-shell'; | ||
import { | ||
REQUEST_URL, | ||
ORIGIN_URL, | ||
Bootloader, | ||
BootloaderConfig, | ||
AppConfig | ||
} from 'angular2-universal'; | ||
import { AppComponent } from './app/'; | ||
|
||
const bootloaderConfig: BootloaderConfig = { | ||
platformProviders: [ | ||
APP_SHELL_BUILD_PROVIDERS, | ||
provide(ORIGIN_URL, { | ||
useValue: 'http://localhost:4200' // full urls are needed for node xhr | ||
}), | ||
provide(APP_BASE_HREF, { useValue: '/' }), | ||
], | ||
async: true, | ||
preboot: false | ||
} | ||
|
||
const appConfig: AppConfig = { | ||
directives: [ | ||
// The component that will become the main App Shell | ||
AppComponent | ||
import { NgModule } from '@angular/core'; | ||
import { AppShellModule } from '@angular/app-shell'; | ||
import { UniversalModule } from 'angular2-universal'; | ||
import { AppComponent } from './app'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
UniversalModule, | ||
AppShellModule.prerender() | ||
], | ||
providers: [ | ||
// What URL should Angular be treating the app as if navigating | ||
provide(REQUEST_URL, { useValue: '/' }) | ||
] | ||
} | ||
|
||
// The build system will call this function to get a bootloader | ||
export function getBootloader() : Bootloader { | ||
return new Bootloader(bootloaderConfig); | ||
} | ||
|
||
// The build system will call this function with the bootloader from | ||
// getBootloader and the contents of the index page | ||
export function serialize(bootloader: Bootloader, template: string) : string { | ||
appConfig.template = template; | ||
return bootloader.serializeApplication(appConfig); | ||
} | ||
declarations: [AppComponent], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class Module {} |
3 changes: 1 addition & 2 deletions
3
packages/angular-cli/blueprints/ng2/files/__path__/app/app.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* global Zone */ | ||
/** | ||
* This script is meant to be run in a child_process to give fresh | ||
* context to universal (mostly to avoid conflicting angular versions, and stale module caches). | ||
* It can be invoked directly, with absolute paths passed as positional args: | ||
* $ node prerender-bootstrapper.js <project-base-path> <template-path> <app-shell-config-path> | ||
*/ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const ts = require('typescript'); | ||
|
||
const projectRoot = process.argv[2]; | ||
const templatePath = process.argv[3]; | ||
const appShellConfig = process.argv[4]; | ||
const projectNodeModulesDir = path.resolve(projectRoot, '../node_modules'); | ||
|
||
// Require from absolute path to prevent looking up inside of angular-cli | ||
require(`${projectNodeModulesDir}/angular2-universal-polyfills`); | ||
const universal = require(`${projectNodeModulesDir}/angular2-universal`); | ||
|
||
// Manually transpile the TS sources to a temp directory | ||
const tsConfigPath = path.join(projectRoot, 'tsconfig.json'); | ||
const compilerOptions = JSON.parse(fs.readFileSync(tsConfigPath, 'utf-8')); | ||
|
||
const tmpDir = fs.mkdtempSync('/tmp/cli-app-shell'); | ||
const parsedCompilerOpts = ts.convertCompilerOptionsFromJson(Object.assign({}, compilerOptions['compilerOptions'], { | ||
module: 'commonjs', | ||
outDir: tmpDir | ||
})); | ||
const tsProgram = ts.createProgram([appShellConfig], parsedCompilerOpts.options); | ||
tsProgram.emit(); | ||
|
||
// Symlink temp directory node_modules to project's node_modules | ||
fs.symlinkSync(path.join(projectRoot, '../node_modules/'), path.join(tmpDir, 'node_modules'), 'dir'); | ||
|
||
// Path to tmp-dir/main-app-shell.js | ||
const pathToTranspiledConfig = path.resolve(tmpDir, path.relative(projectRoot, appShellConfig).replace(/\.ts$/, '.js')); | ||
|
||
var platformRef = universal.platformUniversalDynamic(); | ||
|
||
var platformConfig = { | ||
ngModule: require(pathToTranspiledConfig).Module, | ||
document: fs.readFileSync(templatePath, 'utf-8'), | ||
preboot: false, | ||
baseUrl: '/', | ||
requestUrl: '/', | ||
originUrl: 'localhost:3000' | ||
}; | ||
|
||
|
||
const zone = Zone.current.fork({ | ||
name: 'UNIVERSAL prerender', | ||
properties: platformConfig | ||
}); | ||
zone.run(() => (platformRef.serializeModule(platformConfig.ngModule, platformConfig)) | ||
.then((html) => { | ||
process.stdout.write(html); | ||
}, (err) => { | ||
process.stderr.write(err); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters