lib/config/buildParser.js
function parseBuild(builds, fileExtensions, fileFactory, npmModulepaths, runtimeOptions, serverConfig, parent, level) {
  if (!parent) {
    numBuilds = 0;
    level = 1;
  }

  // Deprecate sources
  if ('sources' in builds) {
    warn(DEPRECATED_SOURCES, 1);
  }
  // Deprecate targets
  if ('targets' in builds) {
    warn(DEPRECATED_VERSION, 1);
    builds = builds.targets;
  }

  // Support basic mode with single build target
  if (!Array.isArray(builds)) builds = [builds];

  return builds.reduce(
    (builds, buildConfig) => {
      const childBuilds = buildConfig.build || buildConfig.children;
      const options = buildConfig.options;
      const version = buildConfig.version;

      delete buildConfig.build;
      delete buildConfig.options;
      delete buildConfig.version;

      // Deprecate old formats
      if ('js' in buildConfig || 'css' in buildConfig || 'html' in buildConfig || 'targets' in buildConfig) {
        warn(DEPRECATED_VERSION);
        return builds;
      }
      // Deprecate aliases
      if (buildConfig.alias) warn(DEPRECATED_ALIAS, 1);
      // Deprecate modular
      if ('modular' in buildConfig) warn(DEPRECATED_MODULAR, 1);
      // Deprecate sources
      if (buildConfig.sources) warn(DEPRECATED_SOURCES, 1);

      if (buildConfig.bootstrap == null) buildConfig.bootstrap = true;
      if (buildConfig.label == null) buildConfig.label = '';
      if (buildConfig.bundle == null || buildConfig.modular) buildConfig.bundle = true;
      buildConfig.batch = false;
      buildConfig.boilerplate = true;
      buildConfig.index = ++numBuilds;
      buildConfig.level = level;
      buildConfig.parent = parent;
      buildConfig.runtimeOptions = runtimeOptions;
      buildConfig.watchOnly = !buildConfig.output;

      parseInputOutput(buildConfig, fileExtensions, runtimeOptions);
      // Ignore build targets with nulled input (no grep match)
      if (!('input' in buildConfig && buildConfig.input != null)) return builds;

      const build = buildFactory(buildConfig);
      const caches = parent
        ? { fileCache: parent.fileCache, resolverCache: parent.resolverCache }
        : cache.createCaches(runtimeOptions.watch);

      build.browser = parent ? parent.browser : buildPlugins.isBrowserEnvironment(version);
      build.fileCache = caches.fileCache;
      build.resolverCache = caches.resolverCache;
      build.fileFactoryOptions = getFileFactoryOptions(build, parent, version, options, {
        fileExtensions,
        fileFactory,
        npmModulepaths,
        runtimeOptions,
        sourceroot: serverConfig.sourceroot,
        webroot: serverConfig.webroot
      });
      build.fileFactory = build.fileFactoryOptions.fileFactory;
      // Flag as app server target
      build.isAppServer = isAppServer(build.inputpaths, serverConfig);

      // Traverse child build targets
      if (childBuilds) {
        build.builds = parseBuild(
          childBuilds,
          fileExtensions,
          fileFactory,
          npmModulepaths,
          runtimeOptions,
          serverConfig,
          build,
          level + 1
        );
        parseChildInputpaths(build);
      }

      builds.push(build);

      return builds;
    },
    []
  );
}
function parseBuild(builds, fileExtensions, fileFactory, npmModulepaths, runtimeOptions, serverConfig, parent, level) {
  if (!parent) {
    numBuilds = 0;
    level = 1;
  }

  // Deprecate sources
  if ('sources' in builds) {
    warn(DEPRECATED_SOURCES, 1);
  }
  // Deprecate targets
  if ('targets' in builds) {
    warn(DEPRECATED_VERSION, 1);
    builds = builds.targets;
  }

  // Support basic mode with single build target
  if (!Array.isArray(builds)) builds = [builds];

  return builds.reduce(
    (builds, buildConfig) => {
      const childBuilds = buildConfig.build || buildConfig.children;
      const options = buildConfig.options;
      const version = buildConfig.version;

      delete buildConfig.build;
      delete buildConfig.options;
      delete buildConfig.version;

      // Deprecate old formats
      if ('js' in buildConfig || 'css' in buildConfig || 'html' in buildConfig || 'targets' in buildConfig) {
        warn(DEPRECATED_VERSION);
        return builds;
      }
      // Deprecate aliases
      if (buildConfig.alias) warn(DEPRECATED_ALIAS, 1);
      // Deprecate modular
      if ('modular' in buildConfig) warn(DEPRECATED_MODULAR, 1);
      // Deprecate sources
      if (buildConfig.sources) warn(DEPRECATED_SOURCES, 1);

      if (buildConfig.bootstrap == null) buildConfig.bootstrap = true;
      if (buildConfig.label == null) buildConfig.label = '';
      if (buildConfig.bundle == null || buildConfig.modular) buildConfig.bundle = true;
      buildConfig.batch = false;
      buildConfig.boilerplate = true;
      buildConfig.index = ++numBuilds;
      buildConfig.level = level;
      buildConfig.parent = parent;
      buildConfig.runtimeOptions = runtimeOptions;
      buildConfig.watchOnly = !buildConfig.output;

      parseInputOutput(buildConfig, fileExtensions, runtimeOptions);
      // Ignore build targets with nulled input (no grep match)
      if (!('input' in buildConfig && buildConfig.input != null)) return builds;

      const build = buildFactory(buildConfig);
      const caches = parent
        ? { fileCache: parent.fileCache, resolverCache: parent.resolverCache }
        : cache.createCaches(runtimeOptions.watch);

      build.browser = parent ? parent.browser : buildPlugins.isBrowserEnvironment(version);
      build.fileCache = caches.fileCache;
      build.resolverCache = caches.resolverCache;
      build.fileFactoryOptions = getFileFactoryOptions(build, parent, version, options, {
        fileExtensions,
        fileFactory,
        npmModulepaths,
        runtimeOptions,
        sourceroot: serverConfig.sourceroot,
        webroot: serverConfig.webroot
      });
      build.fileFactory = build.fileFactoryOptions.fileFactory;
      // Flag as app server target
      build.isAppServer = isAppServer(build.inputpaths, serverConfig);

      // Traverse child build targets
      if (childBuilds) {
        build.builds = parseBuild(
          childBuilds,
          fileExtensions,
          fileFactory,
          npmModulepaths,
          runtimeOptions,
          serverConfig,
          build,
          level + 1
        );
        parseChildInputpaths(build);
      }

      builds.push(build);

      return builds;
    },
    []
  );
}
function parseBuild ( builds , fileExtensions , fileFactory , npmModulepaths , runtimeOptions , serverConfig , parent , level ) { if ( ! parent ) { numBuilds = 0 ; level = 1 ; } // Deprecate sources if ( 'sources' in builds ) { warn ( DEPRECATED_SOURCES , 1 ) ; } // Deprecate targets if ( 'targets' in builds ) { warn ( DEPRECATED_VERSION , 1 ) ; builds = builds . targets ; } // Support basic mode with single build target if ( ! Array . isArray ( builds ) ) builds = [ builds ] ; return builds . reduce ( ( builds , buildConfig ) => { const childBuilds = buildConfig . build || buildConfig . children ; const options = buildConfig . options ; const version = buildConfig . version ; delete buildConfig . build ; delete buildConfig . options ; delete buildConfig . version ; // Deprecate old formats if ( 'js' in buildConfig || 'css' in buildConfig || 'html' in buildConfig || 'targets' in buildConfig ) { warn ( DEPRECATED_VERSION ) ; return builds ; } // Deprecate aliases if ( buildConfig . alias ) warn ( DEPRECATED_ALIAS , 1 ) ; // Deprecate modular if ( 'modular' in buildConfig ) warn ( DEPRECATED_MODULAR , 1 ) ; // Deprecate sources if ( buildConfig . sources ) warn ( DEPRECATED_SOURCES , 1 ) ; if ( buildConfig . bootstrap == null ) buildConfig . bootstrap = true ; if ( buildConfig . label == null ) buildConfig . label = '' ; if ( buildConfig . bundle == null || buildConfig . modular ) buildConfig . bundle = true ; buildConfig . batch = false ; buildConfig . boilerplate = true ; buildConfig . index = ++ numBuilds ; buildConfig . level = level ; buildConfig . parent = parent ; buildConfig . runtimeOptions = runtimeOptions ; buildConfig . watchOnly = ! buildConfig . output ; parseInputOutput ( buildConfig , fileExtensions , runtimeOptions ) ; // Ignore build targets with nulled input (no grep match) if ( ! ( 'input' in buildConfig && buildConfig . input != null ) ) return builds ; const build = buildFactory ( buildConfig ) ; const caches = parent ? { fileCache : parent . fileCache , resolverCache : parent . resolverCache } : cache . createCaches ( runtimeOptions . watch ) ; build . browser = parent ? parent . browser : buildPlugins . isBrowserEnvironment ( version ) ; build . fileCache = caches . fileCache ; build . resolverCache = caches . resolverCache ; build . fileFactoryOptions = getFileFactoryOptions ( build , parent , version , options , { fileExtensions , fileFactory , npmModulepaths , runtimeOptions , sourceroot : serverConfig . sourceroot , webroot : serverConfig . webroot } ) ; build . fileFactory = build . fileFactoryOptions . fileFactory ; // Flag as app server target build . isAppServer = isAppServer ( build . inputpaths , serverConfig ) ; // Traverse child build targets if ( childBuilds ) { build . builds = parseBuild ( childBuilds , fileExtensions , fileFactory , npmModulepaths , runtimeOptions , serverConfig , build , level + 1 ) ; parseChildInputpaths ( build ) ; } builds . push ( build ) ; return builds ; } , [ ] ) ; }
Parse and validate build targets
@param {Array} builds
@param {Object} fileExtensions
@param {Function} fileFactory
@param {Array} npmModulepaths
@param {Object} runtimeOptions
@param {Object} serverConfig
@param {Object} [parent]
@param {Number} [level]
@returns {Array}
Parse and validate build targets