Skip to content

Instantly share code, notes, and snippets.

@william-lohan
Last active December 6, 2017 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save william-lohan/d4aac80c2d22f130babcc55515aaed85 to your computer and use it in GitHub Desktop.
Save william-lohan/d4aac80c2d22f130babcc55515aaed85 to your computer and use it in GitHub Desktop.
platform-electron
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"apps": [
{
"name": "electron",
"root": "src",
"outDir": "dist/electron/",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.electron.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.electron.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
]
}
import { NgModule, createPlatformFactory, platformCore, StaticProvider, PLATFORM_ID, PLATFORM_INITIALIZER, COMPILER_OPTIONS } from '@angular/core';
import { PlatformLocation } from '@angular/common';
import { ResourceLoader } from '@angular/compiler';
import { BrowserModule, DOCUMENT, ɵBrowserPlatformLocation as BrowserPlatformLocation, ɵBrowserDomAdapter as BrowserDomAdapter, ɵBrowserGetTestability as BrowserGetTestability } from '@angular/platform-browser';
import { ɵplatformCoreDynamic as platformCoreDynamic, ɵResourceLoaderImpl as ResourceLoaderImpl } from '@angular/platform-browser-dynamic';
import { PLATFORM_ELECTRON_ID } from './platform_id';
export function initDomAdapter() {
BrowserDomAdapter.makeCurrent();
BrowserGetTestability.init();
}
export function _document(): any {
return document;
}
export const INTERNAL_ELECTRON_PLATFORM_PROVIDERS: StaticProvider[] = [
{ provide: PLATFORM_ID, useValue: PLATFORM_ELECTRON_ID },
{ provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true },
{ provide: PlatformLocation, useClass: BrowserPlatformLocation, deps: [DOCUMENT] },
{ provide: DOCUMENT, useFactory: _document, deps: [] },
];
export const INTERNAL_ELECTRON_DYNAMIC_PLATFORM_PROVIDERS: StaticProvider[] = [
INTERNAL_ELECTRON_PLATFORM_PROVIDERS,
{
provide: COMPILER_OPTIONS,
useValue: { providers: [{ provide: ResourceLoader, useClass: ResourceLoaderImpl, deps: [] }] },
multi: true
},
{ provide: PLATFORM_ID, useValue: PLATFORM_ELECTRON_ID }
];
/**
* For AOT
* @example
* ```ts
* platformElectron().bootstrapModuleFactory(AppElectronModuleNgFactory);
* ```
*/
export const platformElectron = createPlatformFactory(platformCore, 'electron', INTERNAL_ELECTRON_PLATFORM_PROVIDERS);
/**
* For JIT
* @example
* ```ts
* platformElectronDynamic().bootstrapModule(AppElectronModule);
* ```
*/
export const platformElectronDynamic = createPlatformFactory(platformCoreDynamic, 'electronDynamic', INTERNAL_ELECTRON_DYNAMIC_PLATFORM_PROVIDERS);
export const ELECTRON = new InjectionToken<RendererInterface>('electron');
export function _electron() {
return (window as any).require('electron');
}
/**
* re-exports BrowserModule
* ```ts
* @NgModule({
* imports: [
* AppModule,
* ElectronModule
* ],
* bootstrap: [AppComponent]
* })
* export class AppElectronModule { }
* ```
*/
@NgModule({
exports: [
BrowserModule
],
providers: [
{ provide: ELECTRON, useFactory: _electron(), deps: [] }
]
})
export class ElectronModule { }
import { enableProdMode } from '@angular/core';
import { platformElectron } from './platform-electron/electron';
import { AppElectronModuleNgFactory } from './app/app.electron.module.ngfactory';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformElectron().bootstrapModuleFactory(AppElectronModuleNgFactory)
.catch(err => console.log(err));
export const PLATFORM_ELECTRON_ID = 'electron';
/**
* Returns whether a platform id represents a electron platform.
*/
export function isPlatformElectron(platformId: Object): boolean {
return platformId === PLATFORM_ELECTRON_ID;
}
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist/electron/",
"baseUrl": "./",
"module": "commonjs",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"angularCompilerOptions": {
"entryModule": "app/app.electron.module#AppElectronModule"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment