• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript polymer-build.addServiceWorker函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: waitFor

 let unbundledPostProcessing = Promise.all([loadSWConfig, waitFor(unbundledPhase)]).then((results) => {
   let swConfig: SWConfig = results[0];
   return addServiceWorker({
     buildRoot: 'build/unbundled',
     project: polymerProject,
     swConfig: swConfig,
   });
 });
开发者ID:mbn18,项目名称:polymer-cli,代码行数:8,代码来源:build.ts


示例2: build


//.........这里部分代码省略.........
  }

  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(
      polymerProject.config.root,
      options.swPrecacheConfig || 'sw-precache-config.js');
  let swConfig: SWConfig|null = null;
  if (options.addServiceWorker) {
    swConfig = await loadServiceWorkerConfig(swPrecacheConfigPath);
  }

  // There is nothing left to do, so wait for the build stream to complete.
  await waitFor(buildStream);

  if (options.addServiceWorker) {
    logger.debug(`Generating service worker...`);
    if (swConfig) {
      logger.debug(`Service worker config found`, swConfig);
    } else {
      logger.debug(
          `No service worker configuration found at ` +
          `${swPrecacheConfigPath}, continuing with defaults`);
    }
    await addServiceWorker({
      buildRoot: buildDirectory,
      project: polymerProject,
      swPrecacheConfig: swConfig || undefined,
      bundled: bundled,
    });
  }

  logger.info(`(${buildName}) Build complete!`);
}
开发者ID:asdfg9822,项目名称:polymer-cli,代码行数:101,代码来源:build.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript polymer-build.forkStream函数代码示例发布时间:2022-05-25
下一篇:
TypeScript html-parser.HtmlParser类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap