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


TypeScript BuilderContext.validateOptions方法代碼示例

本文整理匯總了TypeScript中@angular-devkit/architect.BuilderContext.validateOptions方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BuilderContext.validateOptions方法的具體用法?TypeScript BuilderContext.validateOptions怎麽用?TypeScript BuilderContext.validateOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@angular-devkit/architect.BuilderContext的用法示例。


在下文中一共展示了BuilderContext.validateOptions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: setup

  async function setup(): Promise<{
    browserOptions: json.JsonObject & BrowserBuilderSchema,
    webpackConfig: webpack.Configuration,
    webpackDevServerConfig: WebpackDevServer.Configuration,
    port: number,
  }> {
    // Get the browser configuration from the target name.
    const rawBrowserOptions = await context.getTargetOptions(browserTarget);

    // Override options we need to override, if defined.
    const overrides = (Object.keys(options) as (keyof DevServerBuilderOptions)[])
    .filter(key => options[key] !== undefined && devServerBuildOverriddenKeys.includes(key))
    .reduce<json.JsonObject & Partial<BrowserBuilderSchema>>((previous, key) => ({
      ...previous,
      [key]: options[key],
    }), {});

    // In dev server we should not have budgets because of extra libs such as socks-js
    overrides.budgets = undefined;

    const browserName = await context.getBuilderNameForTarget(browserTarget);
    const browserOptions = await context.validateOptions<json.JsonObject & BrowserBuilderSchema>(
      { ...rawBrowserOptions, ...overrides },
      browserName,
    );

    const webpackConfigResult = await buildBrowserWebpackConfigFromContext(
      browserOptions,
      context,
      host,
    );

    // No differential loading for dev-server, hence there is just one config
    let webpackConfig = webpackConfigResult.config[0];

    const port = await checkPort(options.port || 0, options.host || 'localhost', 4200);
    const webpackDevServerConfig = webpackConfig.devServer = buildServerConfig(
      root,
      options,
      browserOptions,
      context.logger,
    );

    if (transforms.webpackConfiguration) {
      webpackConfig = await transforms.webpackConfiguration(webpackConfig);
    }

    return { browserOptions, webpackConfig, webpackDevServerConfig, port };
  }
開發者ID:angular,項目名稱:angular-cli,代碼行數:49,代碼來源:index.ts

示例2: execute

async function execute(options: ExtractI18nBuilderOptions, context: BuilderContext) {
  // Check Angular version.
  Version.assertCompatibleAngularVersion(context.workspaceRoot);

  const browserTarget = targetFromTargetString(options.browserTarget);
  const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderOptions>(
    await context.getTargetOptions(browserTarget),
    await context.getBuilderNameForTarget(browserTarget),
  );

  // We need to determine the outFile name so that AngularCompiler can retrieve it.
  let outFile = options.outFile || getI18nOutfile(options.i18nFormat);
  if (options.outputPath) {
    // AngularCompilerPlugin doesn't support genDir so we have to adjust outFile instead.
    outFile = path.join(options.outputPath, outFile);
  }

  const { config } = await generateBrowserWebpackConfigFromContext(
    {
      ...browserOptions,
      optimization: {
        scripts: false,
        styles: false,
      },
      i18nLocale: options.i18nLocale,
      i18nFormat: options.i18nFormat,
      i18nFile: outFile,
      aot: true,
      progress: options.progress,
      assets: [],
      scripts: [],
      styles: [],
      deleteOutputPath: false,
    },
    context,
    wco => [
      { plugins: [new InMemoryOutputPlugin()] },
      getCommonConfig(wco),
      getAotConfig(wco, true),
      getStylesConfig(wco),
      getStatsConfig(wco),
    ],
  );

  return runWebpack(config[0], context).toPromise();
}
開發者ID:angular,項目名稱:angular-cli,代碼行數:46,代碼來源:index.ts

示例3: _renderUniversal

async function _renderUniversal(
  options: BuildWebpackAppShellSchema,
  context: BuilderContext,
  browserResult: BrowserBuilderOutput,
  serverResult: ServerBuilderOutput,
): Promise<BrowserBuilderOutput> {
  const browserIndexOutputPath = path.join(browserResult.outputPath || '', 'index.html');
  const indexHtml = fs.readFileSync(browserIndexOutputPath, 'utf8');
  const serverBundlePath = await _getServerModuleBundlePath(options, context, serverResult);

  const root = context.workspaceRoot;
  requireProjectModule(root, 'zone.js/dist/zone-node');

  const renderModuleFactory = requireProjectModule(
    root,
    '@angular/platform-server',
  ).renderModuleFactory;
  const AppServerModuleNgFactory = require(serverBundlePath).AppServerModuleNgFactory;
  const outputIndexPath = options.outputIndexPath
    ? path.join(root, options.outputIndexPath)
    : browserIndexOutputPath;

  // Render to HTML and overwrite the client index file.
  const html = await renderModuleFactory(AppServerModuleNgFactory, {
    document: indexHtml,
    url: options.route,
  });

  fs.writeFileSync(outputIndexPath, html);

  const browserTarget = targetFromTargetString(options.browserTarget);
  const rawBrowserOptions = await context.getTargetOptions(browserTarget);
  const browserBuilderName = await context.getBuilderNameForTarget(browserTarget);
  const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderSchema>(
    rawBrowserOptions,
    browserBuilderName,
  );

  if (browserOptions.serviceWorker) {
    const host = new NodeJsSyncHost();
    // Create workspace.
    const registry = new schema.CoreSchemaRegistry();
    registry.addPostTransform(schema.transforms.addUndefinedDefaults);

    const workspace = await experimental.workspace.Workspace.fromPath(
      host,
      normalize(context.workspaceRoot),
      registry,
    );
    const projectName = context.target ? context.target.project : workspace.getDefaultProjectName();

    if (!projectName) {
      throw new Error('Must either have a target from the context or a default project.');
    }
    const projectRoot = resolve(
      workspace.root,
      normalize(workspace.getProject(projectName).root),
    );

    await augmentAppWithServiceWorker(
      host,
      normalize(root),
      projectRoot,
      join(normalize(root), browserOptions.outputPath),
      browserOptions.baseHref || '/',
      browserOptions.ngswConfigPath,
    );
  }

  return browserResult;
}
開發者ID:angular,項目名稱:angular-cli,代碼行數:71,代碼來源:index.ts


注:本文中的@angular-devkit/architect.BuilderContext.validateOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。