当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript PolymerProject.splitHtml方法代码示例

本文整理汇总了TypeScript中polymer-build.PolymerProject.splitHtml方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PolymerProject.splitHtml方法的具体用法?TypeScript PolymerProject.splitHtml怎么用?TypeScript PolymerProject.splitHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在polymer-build.PolymerProject的用法示例。


在下文中一共展示了PolymerProject.splitHtml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: PolymerProject

  return new Promise<any>((buildResolve, _) => {
    let polymerProject = new PolymerProject({
      root: config.root,
      shell: config.shell,
      entrypoint: config.entrypoint,
      fragments: config.fragments,
      sourceGlobs: options.sources,
      includeDependencies: options.includeDependencies,
    });

    if (options.insertDependencyLinks) {
      logger.debug(`Additional dependency links will be inserted into application`);
    }

    // mix in optimization options from build command
    // TODO: let this be set by the user
    let optimizeOptions = {
      html: Object.assign({removeComments: true}, options.html),
      css: Object.assign({stripWhitespace: true}, options.css),
      js: Object.assign({minify: true}, options.js),
    };

    logger.info(`Building application...`);

    logger.debug(`Reading source files...`);
    let sourcesStream = polymerProject.sources()
      .pipe(polymerProject.splitHtml())
      .pipe(gulpif(/\.js$/, uglify(optimizeOptions.js)))
      .pipe(gulpif(/\.css$/, cssSlam(optimizeOptions.css)))
      .pipe(gulpif(/\.html$/, htmlmin(optimizeOptions.html)))
      .pipe(polymerProject.rejoinHtml());

    logger.debug(`Reading dependencies...`);
    let depsStream = polymerProject.dependencies()
      .pipe(polymerProject.splitHtml())
      .pipe(polymerProject.rejoinHtml());

    let buildStream = mergeStream(sourcesStream, depsStream)
      .once('data', () => { logger.debug('Analyzing build dependencies...'); })
      .pipe(polymerProject.analyzer);

    let unbundledPhase = forkStream(buildStream)
      .once('data', () => { logger.info('Generating build/unbundled...'); })
      .pipe(
        gulpif(
          options.insertDependencyLinks,
          new PrefetchTransform(polymerProject.root, polymerProject.entrypoint,
            polymerProject.shell, polymerProject.fragments,
            polymerProject.analyzer)
        )
      )
      .pipe(gulp.dest('build/unbundled'));

    let bundledPhase = forkStream(buildStream)
      .once('data', () => { logger.info('Generating build/bundled...'); })
      .pipe(polymerProject.bundler)
      .pipe(gulp.dest('build/bundled'));

    let swPrecacheConfig = path.resolve(polymerProject.root, options.swPrecacheConfig || 'sw-precache-config.js');
    let loadSWConfig = parsePreCacheConfig(swPrecacheConfig);

    loadSWConfig.then((swConfig) => {
      if (swConfig) {
        logger.debug(`Service worker config found`, swConfig);
      } else {
        logger.debug(`No service worker configuration found at ${swPrecacheConfig}, continuing with defaults`);
      }
    });

    // Once the unbundled build stream is complete, create a service worker for the build
    let unbundledPostProcessing = Promise.all([loadSWConfig, waitFor(unbundledPhase)]).then((results) => {
      let swConfig: SWConfig = results[0];
      return addServiceWorker({
        buildRoot: 'build/unbundled',
        project: polymerProject,
        swConfig: swConfig,
      });
    });

    // Once the bundled build stream is complete, create a service worker for the build
    let bundledPostProcessing = Promise.all([loadSWConfig, waitFor(bundledPhase)]).then((results) => {
      let swConfig: SWConfig = results[0];
      return addServiceWorker({
        buildRoot: 'build/bundled',
        project: polymerProject,
        swConfig: swConfig,
        bundled: true,
      });
    });

    return Promise.all([unbundledPostProcessing, bundledPostProcessing]).then(() => {
      logger.info('Build complete!');
      buildResolve();
    });

  });
开发者ID:mbn18,项目名称:polymer-cli,代码行数:96,代码来源:build.ts

示例2: PolymerProject

  return new Promise<any>((buildResolve, _) => {
    let polymerProject = new PolymerProject({
      root: config.root,
      shell: config.shell,
      entrypoint: config.entrypoint,
      fragments: config.fragments,
      sourceGlobs: options.sources,
      includeDependencies: options.includeDependencies,
    });

    if (options.insertDependencyLinks) {
      logger.debug(`Additional dependency links will be inserted into application`);
    }

    // mix in optimization options from build command
    // TODO: let this be set by the user
    let optimizeOptions = {
      html: Object.assign({removeComments: true}, options.html),
      css: Object.assign({stripWhitespace: true}, options.css),
      js: Object.assign({minify: true}, options.js),
    };

    logger.info(`Building application...`);

    logger.debug(`Reading source files...`);
    let sourcesStream = polymerProject.sources()
      .pipe(polymerProject.splitHtml())
      .pipe(gulpif(/\.js$/, uglify(optimizeOptions.js)))
      .pipe(gulpif(/\.css$/, cssSlam(optimizeOptions.css)))
      .pipe(gulpif(/\.html$/, htmlmin(optimizeOptions.html)))
      .pipe(polymerProject.rejoinHtml());

    logger.debug(`Reading dependencies...`);
    let depsStream = polymerProject.dependencies()
      .pipe(polymerProject.splitHtml())
      .pipe(polymerProject.rejoinHtml());

    let buildStream = mergeStream(sourcesStream, depsStream)
      .once('data', () => { logger.debug('Analyzing build dependencies...'); })
      .pipe(polymerProject.analyze);

    let serviceWorkerName = 'service-worker.js';

    let unbundledPhase = forkStream(buildStream)
      .once('data', () => { logger.info('Generating build/unbundled...'); })
      .pipe(
        gulpif(
          options.insertDependencyLinks,
          new PrefetchTransform(polymerProject.root, polymerProject.entrypoint,
            polymerProject.shell, polymerProject.fragments,
            polymerProject.analyze)
        )
      )
      .pipe(gulp.dest('build/unbundled'));

    let bundledPhase = forkStream(buildStream)
      .once('data', () => { logger.info('Generating build/bundled...'); })
      .pipe(polymerProject.bundle)
      .pipe(gulp.dest('build/bundled'));


    let genSW = (buildRoot: string, deps: string[], swConfig: SWConfig, scriptAndStyleDeps?: string[]) => {
      logger.debug(`Generating service worker for ${buildRoot}...`);
      logger.debug(`Script and style deps: ${scriptAndStyleDeps}`);
      return generateServiceWorker({
        root: polymerProject.root,
        entrypoint: polymerProject.entrypoint,
        deps,
        scriptAndStyleDeps,
        buildRoot,
        swConfig: clone(swConfig),
        serviceWorkerPath: path.join(polymerProject.root, buildRoot, serviceWorkerName),
      });
    };

    let swPrecacheConfig = path.resolve(polymerProject.root, options.swPrecacheConfig || 'sw-precache-config.js');
    return Promise.all([
      parsePreCacheConfig(swPrecacheConfig),
      polymerProject.analyze.analyzeDependencies,
      waitForAll([unbundledPhase, bundledPhase])
    ]).then((results) => {
      let swConfig: SWConfig = results[0];
      let depsIndex: DepsIndex = results[1];

      if (swConfig) {
        logger.debug(`Service worker config found`, swConfig);
      } else {
        logger.debug(`No service worker configuration found at ${swPrecacheConfig}, continuing with defaults`);
      }

      let unbundledDeps = polymerProject.analyze.allFragments
          .concat(Array.from(depsIndex.depsToFragments.keys()));
      let bundledDeps = polymerProject.analyze.allFragments
          .concat(polymerProject.bundle.sharedBundleUrl);
      let fullDeps = Array.from(depsIndex.fragmentToFullDeps.values());
      let scriptAndStyleDeps = new Set<string>();
      fullDeps.forEach(d => {
        d.scripts.forEach((s) => scriptAndStyleDeps.add(s));
        d.styles.forEach((s) => scriptAndStyleDeps.add(s));
      });
//.........这里部分代码省略.........
开发者ID:catiejojo,项目名称:polymer-cli,代码行数:101,代码来源:build.ts


注:本文中的polymer-build.PolymerProject.splitHtml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。