How to use angular2-gulp-prerender - 4 common examples

To help you get started, we’ve selected a few angular2-gulp-prerender examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github justindujardin / ng2-material / modules / router / gulpfile.ts View on Github external
function renderAsPath(routePath: string = '', outPath: string = '') {

  // Resolve
  let distBase = path.resolve(path.join(__dirname, 'dist'));
  outPath = path.join(distBase, outPath);
  let relativePath = path.relative(outPath, distBase);
  // add a . to no relative path result because we prepend
  // to a / for BASE_URL below. 
  if (relativePath === '') {
    relativePath = '.';
  }

  let stableTime: number = -1;
  let baseUrl = '/';
  return gulp.src('./index.html')
    .pipe(prerender({
      directives: [Html],
      // NOTE: It is assumed that this is not called until the zone is stable.
      ngOnStable: () => {
        return new Promise((resolve) => {
          setTimeout(resolve, 500);
        });
      },
      providers: [
        provide(APP_BASE_HREF, {useValue: baseUrl}),
        provide(BASE_URL, {useValue: relativePath + '/'}),
        provide(REQUEST_URL, {useValue: `${baseUrl}${routePath}`}),
        provide(UrlResolver, {useValue: new NodeUrlResolver}),
        NODE_ROUTER_PROVIDERS,
        NODE_HTTP_PROVIDERS,
      ],
      preboot: false,
github justindujardin / ng2-material / modules / site / gulpfile.ts View on Github external
function renderAsPath(routePath: string = '', outPath: string = '') {

  // Resolve
  let distBase = path.resolve(path.join(__dirname, 'dist'));
  outPath = path.join(distBase, outPath);
  let relativePath = path.relative(outPath, distBase);
  // add a . to no relative path result because we prepend
  // to a / for BASE_URL below. 
  if (relativePath === '') {
    relativePath = '.';
  }
  let baseUrl = '/';
  return gulp.src('./index.html')
    .pipe(prerender({
      directives: [Html],
      // TODO: This is a hack to wait for components to render because Universal
      // does not patch fs and wait for my fs calls to complete.
      ngOnStable: () => new Promise((resolve) => setTimeout(resolve, 500)),
      platformProviders: [
        // provide(APP_BASE_HREF, {useValue: baseUrl}),
        provide(BASE_URL, {useValue: relativePath + '/'}),
        provide(ORIGIN_URL, {useValue: '/'}),
        provide(REQUEST_URL, {useValue: `${baseUrl}${routePath}`}),
        provide(UrlResolver, {useValue: new NodeUrlResolver}),
        NODE_ROUTER_PROVIDERS,
        NODE_HTTP_PROVIDERS,
      ],
      preboot: true,
      async: true
    }))
github justindujardin / ng2-material / example / gulpfile.ts View on Github external
gulp.task('prerender', () => {
  let baseUrl = '/';

  let dirs:any[] = [App];
  return gulp.src('./index.html')
    .pipe(prerender({
      directives: dirs,
      providers: [
        provide(APP_BASE_HREF, {useValue: baseUrl}),
        provide(BASE_URL, {useValue: path.resolve(__dirname)}),
        provide(REQUEST_URL, {useValue: path.resolve(__dirname)}),
        provide(UrlResolver, {useValue: new NodeUrlResolver}),
        DEMO_PROVIDERS,
        NODE_ROUTER_PROVIDERS,
        NODE_HTTP_PROVIDERS,
      ],
      platformProviders: [MATERIAL_NODE_PROVIDERS],
      preboot: false,
      async: true
    }))
    .pipe(gulp.dest('dist'));
});
github angular / universal-starter / gulpfile.ts View on Github external
gulp.task('prerender', () => {

  return gulp.src('./src/index.html')
    .pipe(prerender({
      directives: [ App, Title, ServerOnlyApp ],
      providers: [
        provide(APP_BASE_HREF, {useValue: '/'}),
        provide(REQUEST_URL, {useValue: '/'}),
        ROUTER_PROVIDERS,
        NODE_LOCATION_PROVIDERS,
      ],
      preboot: true
    }))
    .pipe(gulp.dest('dist'));
});

angular2-gulp-prerender

Prerender your Universal (isomorphic) Angular 2 app

MIT
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular angular2-gulp-prerender functions

Similar packages