當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript polymer-build.addServiceWorker函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。