import { ResourceLoader } from '@angular/compiler' ; import { COMPILER_OPTIONS , createPlatformFactory , Injectable , ModuleWithComponentFactories , PlatformRef , StaticProvider , ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS } from '@angular/core' ; import { JitCompilerFactory as _JitCompilerFactory , ɵplatformCoreDynamic as platformCoreDynamic , ɵResourceLoaderImpl as ResourceLoaderBrowserImpl } from '@angular/platform-browser-dynamic' ; import { PLATFORM_CLOUD_BROWSER_PROVIDERS , PLATFORM_CLOUD_SERVER_PROVIDERS , PLATFORM_CLOUD_SHARED_PROVIDERS } from '@angular/platform-cloud' ; declare var require ; @ Injectable ( ) export class ResourceLoaderServerImpl extends ResourceLoader { fs = require ( 'fs' ) ; path = require ( 'path' ) ; constructor ( ) { super ( ) ; } get ( url ) { return new Promise ( ( res ) => { const path = this . path . resolve ( url ) ; this . fs . readFile ( path , ( err , data ) => res ( data . toString ( 'utf-8' ) ) ) ; } ) ; } } export const platformCloudServerDynamic = createPlatformFactory ( platformCoreDynamic , 'cloudServerDynamic' , [ { provide : COMPILER_OPTIONS , useValue : { providers : [ { provide : ResourceLoader , useClass : ResourceLoaderServerImpl , deps : [ ] } ] } , multi : true } , { provide : ALLOW_MULTIPLE_PLATFORMS , useValue : true } , PLATFORM_CLOUD_SHARED_PROVIDERS , PLATFORM_CLOUD_SERVER_PROVIDERS ] ) ; export const platformCloudBrowserDynamic = createPlatformFactory ( platformCoreDynamic , 'cloudBrowserDynamic' , [ { provide : COMPILER_OPTIONS , useValue : { providers : [ { provide : ResourceLoader , useClass : ResourceLoaderBrowserImpl , deps : [ ] } ] } , multi : true } , PLATFORM_CLOUD_SHARED_PROVIDERS , PLATFORM_CLOUD_BROWSER_PROVIDERS ] ) ; export function bootstrapCloudServerDynamic ( customProviders = [ ] ) { const platform = platformCloudServerDynamic ( customProviders ) ; return Promise . resolve ( platform ) ; } export function bootstrapCloudBrowserDynamic ( customProviders = [ ] ) { const platform = platformCloudBrowserDynamic ( customProviders ) ; return Promise . resolve ( platform ) ; } /**
 * Early hack to speed up JIT restart below.
 */ export function compileModuleAndAllComponentsAsync < T > ( platformRef , module ) { const config = platformRef . injector . get ( COMPILER_OPTIONS ) ; const JitCompilerFactory = _JitCompilerFactory ; const compilerFactory = new JitCompilerFactory ( [ ] ) ; const compiler = compilerFactory . createCompiler ( config ) ; return compiler . compileModuleAndAllComponentsAsync ( module ) ; }