本文整理汇总了TypeScript中angular2-universal.Bootloader类的典型用法代码示例。如果您正苦于以下问题:TypeScript Bootloader类的具体用法?TypeScript Bootloader怎么用?TypeScript Bootloader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bootloader类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generateHtml
export function generateHtml(opts: Options): Promise<string> {
opts = Object.assign({
originUrl: "http://localhost:8080",
baseUrl: "/",
reqUrl: "/",
preboot: false,
}, opts);
let config: CliBootloaderConfig = {
directives: [opts.component],
platformProviders: [
provide(ORIGIN_URL, { useValue: opts.originUrl }),
provide(BASE_URL, { useValue: opts.baseUrl }),
],
providers: [
provide(REQUEST_URL, { useValue: opts.reqUrl }),
...NODE_ROUTER_PROVIDERS,
...NODE_HTTP_PROVIDERS,
],
beautify: true,
async: true,
};
enableProdMode();
let doc = Bootloader.parseDocument(opts.templateHtml);
config.document = doc;
config.template = opts.templateHtml;
config.preboot = opts.preboot;
let bootloader = new Bootloader(config);
return bootloader.serializeApplication();
}
示例2: function
AppShellPlugin.prototype.build = function () {
var sourceHtml = fse.readFileSync(path.resolve(this.inputPaths[0], this.indexPath), 'utf-8');
var options = {
document: Bootloader.parseDocument(sourceHtml),
directives: [ IssueCliApp ],
providers: [
provide(APP_BASE_HREF, {useValue: '/'}),
provide(REQUEST_URL, {useValue: '/'}),
provide(IS_POST_LOGIN, {
useValue: false
}),
ROUTER_PROVIDERS,
NODE_LOCATION_PROVIDERS,
provide(IS_PRERENDER, {
useValue: true
}),
FIREBASE_PROVIDERS,
NODE_HTTP_PROVIDERS,
provide(LOCAL_STORAGE, {
useValue: {
getItem: () => null,
setItem: () => null
}
}),
defaultFirebase('https://issue-zero.firebaseio.com')
],
preboot: false
}
var bootloader = Bootloader.create(options);
return bootloader.serializeApplication().then(html => fse.outputFileSync(path.resolve(this.outputPath, this.indexPath), html, 'utf-8'));
}
示例3: build
build() {
var sourceHtml = fs.readFileSync(path.resolve(this.inputPaths[0], this.indexPath), 'utf-8');
var appShellOptions = require(path.resolve(this.inputPaths[0], this.appShellPath)).options;
var options = Object.assign(appShellOptions, {
document: Bootloader.parseDocument(sourceHtml),
});
var bootloader = Bootloader.create(options);
return bootloader.serializeApplication()
.then(html => fs.writeFileSync(path.resolve(this.outputPath, this.indexPath), html, 'utf-8'));
}
示例4: build
build() {
var sourceHtml = fs.readFileSync(path.resolve(this.inputPaths[0], this.indexPath), 'utf-8');
var appShellOptions = require(path.resolve(this.inputPaths[0], this.appShellPath)).options;
var options = Object.assign(appShellOptions, {
document: Bootloader.parseDocument(sourceHtml),
});
var bootloader = Bootloader.create(options);
// Make sure to get all providers and platformProviders
var providers = [].concat(options.providers || []).concat(options.platformProviders || []);
return bootloader.serializeApplication(null, providers)
.then(html => fs.writeFileSync(path.resolve(this.outputPath, this.indexPath), html, 'utf-8'));
}
示例5: bootstrap
export function bootstrap(appComponentType: any, appProviders: Array<Type | Provider | any | any[]> = []): Promise<ComponentRef<any>> {
let combinedProviders = [
IOT_PROVIDERS,
...appProviders
];
const bootloader = Bootloader.create({
providers: combinedProviders
});
return bootloader.bootstrap(appComponentType);
}
示例6: queryParamsToBoolean
export const ngApp = (req, res) => {
let baseUrl = '/';
let url = req.originalUrl || '/';
let queryParams: any = queryParamsToBoolean(req.query);
let bootloader = new Bootloader({
template: `
<!doctype html>
<html>
<head>
<title>Angular 2 Universal Starter</title>
<meta charset="UTF-8">
<meta name="description" content="Angular 2 Universal">
<meta name="keywords" content="Angular 2,Universal">
<meta name="author" content="PatrickJS">
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<base href="/">
</head>
<body>
<app>... Loading Universal ...</app>
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>
<script src="/main.js"></script>
</body>
</html>
`,
directives: [ App ],
providers: [
provide(ORIGIN_URL, {useValue: 'http://localhost:3000'}),
provide(BASE_URL, {useValue: baseUrl}),
provide(REQUEST_URL, { useValue: 'req.originalUrl' }),
NODE_ROUTER_PROVIDERS,
NODE_HTTP_PROVIDERS
],
async: queryParams.async === false ? false : true,
preboot: queryParams.preboot === false ? null : {debug: true, uglify: false}
});
bootloader.serializeApplication()
.then(html => res.send(html));
};
示例7: ngApp
export function ngApp(req, res) {
const url = req.originalUrl || '/';
const APP_CONFIG = {
template: `
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Angular 2 Universal Starter</title>
<meta name="description" content="Angular 2 Universal">
<meta name="keywords" content="Angular 2, Universal, Webpack">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
<base href="/">
</head>
<body>
<app>... Loading Universal ...</app>
<script src="vendor.js"></script>
<script src="main.js"></script>
</body>
</html>
`,
directives: [App],
providers: [
provide(REQUEST_URL, {useValue: url}),
...NODE_ROUTER_PROVIDERS,
...NODE_HTTP_PROVIDERS
]
};
bootloader.serializeApplication(APP_CONFIG)
.then(html => res.send(html));
};
示例8: ngApp
function ngApp(req, res) {
let url = req.originalUrl || '/';
bootloader.serializeApplication(null, [
provide(REQUEST_URL, {useValue: url}),
...NODE_ROUTER_PROVIDERS,
...NODE_HTTP_PROVIDERS
])
.then(html => res.send(html));
};
示例9: callback
compiler.plugin('emit', (compilation, callback) => {
if (compilation.assets.hasOwnProperty(this.options.templatePath)) {
this.bootloader.serializeApplication({
// or provide template in config.template
template: compilation.assets[this.options.templatePath].source(),
directives: this.options.appConfig.directives,
providers: this.options.appConfig.providers
})
.then(html => {
compilation.assets[this.options.templatePath] = {
source: () => html,
size: () => html.length
};
callback();
});
}
});
示例10: ngApp
export function ngApp(req, res) {
let url = req.originalUrl || '/';
const AppConfig = {
templateUrl: 'main.html',
directives: [AppComponent],
providers: [
{provide: REQUEST_URL, useValue: url},
provideRouter(routes),
...NODE_HTTP_PROVIDERS,
...NODE_LOCATION_PROVIDERS
]
};
bootloader.serializeApplication(AppConfig)
.then(html => res.send(html));
}