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


TypeScript PolymerProject.addPrefetchLinks方法代码示例

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


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

示例1: build

export async function build(
    options: ProjectBuildOptions,
    polymerProject: PolymerProject): Promise<void> {
  const buildName = options.name || 'default';
  const optimizeOptions:
      OptimizeOptions = {css: options.css, js: options.js, html: options.html};

  // If no name is provided, write directly to the build/ directory.
  // If a build name is provided, write to that subdirectory.
  const buildDirectory = path.join(mainBuildDirectoryName, buildName);
  logger.debug(`"${buildDirectory}": Building with options:`, options);

  // Fork the two streams to guarentee we are working with clean copies of each
  // file and not sharing object references with other builds.
  const sourcesStream = forkStream(polymerProject.sources());
  const depsStream = forkStream(polymerProject.dependencies());
  const htmlSplitter = new HtmlSplitter();

  let buildStream: NodeJS.ReadableStream = pipeStreams([
    mergeStream(sourcesStream, depsStream),
    htmlSplitter.split(),
    getOptimizeStreams(optimizeOptions),
    htmlSplitter.rejoin()
  ]);

  const compiledToES5 = !!(optimizeOptions.js && optimizeOptions.js.compile);
  if (compiledToES5) {
    buildStream = buildStream.pipe(polymerProject.addBabelHelpersInEntrypoint())
                      .pipe(polymerProject.addCustomElementsEs5Adapter());
  }

  const bundled = !!(options.bundle);

  async function getPolymerVersion(): Promise<string> {
    return new Promise<string>(
        (resolve, _reject) =>
            bower.commands.list({}, {offline: true})
                .on('end',
                    (result: any) => {
                      if (result && result.dependencies &&
                          result.dependencies.polymer &&
                          result.dependencies.polymer.pkgMeta &&
                          result.dependencies.polymer.pkgMeta.version) {
                        resolve(result.dependencies.polymer.pkgMeta.version);
                      } else {
                        resolve('');
                      }
                    })
                .on('error', (oops: Error) => {
                  resolve('');
                  console.warn(oops.message);
                }));
  }

  if (bundled) {
    // Polymer 1.x and Polymer 2.x deal with relative urls in dom-module
    // templates differently.  Polymer CLI will attempt to provide a sensible
    // default value for the `rewriteUrlsInTemplates` option passed to
    // `polymer-bundler` based on the version of Polymer found in the project's
    // folders.  We will default to Polymer 1.x behavior unless 2.x is found.
    const polymerVersion = await getPolymerVersion();
    const bundlerOptions = {
      rewriteUrlsInTemplates: !polymerVersion.startsWith('2.')
    };
    if (typeof options.bundle === 'object') {
      Object.assign(bundlerOptions, options.bundle);
    }
    buildStream = buildStream.pipe(polymerProject.bundler(bundlerOptions));
  }

  if (options.insertPrefetchLinks) {
    buildStream = buildStream.pipe(polymerProject.addPrefetchLinks());
  }

  buildStream.once('data', () => {
    logger.info(`(${buildName}) Building...`);
  });

  if (options.basePath) {
    let basePath = options.basePath === true ? buildName : options.basePath;
    if (!basePath.startsWith('/')) {
      basePath = '/' + basePath;
    }
    if (!basePath.endsWith('/')) {
      basePath = basePath + '/';
    }
    buildStream = buildStream.pipe(polymerProject.updateBaseTag(basePath));
  }

  if (options.addPushManifest) {
    buildStream = buildStream.pipe(polymerProject.addPushManifest());
  }

  // Finish the build stream by piping it into the final build directory.
  buildStream = buildStream.pipe(dest(buildDirectory));

  // If a service worker was requested, parse the service worker config file
  // while the build is in progress. Loading the config file during the build
  // saves the user ~300ms vs. loading it afterwards.
  const swPrecacheConfigPath = path.resolve(
//.........这里部分代码省略.........
开发者ID:asdfg9822,项目名称:polymer-cli,代码行数:101,代码来源:build.ts


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