packages/create-react-scripts-ssr/scripts/build-server.js
function buildServer() {
  console.log();
  console.log(`${chalk.cyan('SERVER-SIDE')}`);
  console.log('===========================================================');
  fs.emptyDirSync(paths.appServerBuild);
  console.log('Creating a server-side production build...');

  let compiler = webpack(serverlize(paths, config));
  return new Promise((resolve, reject) => {
    compiler.run((err, stats) => {
      if (err) {
        return reject(err);
      } 
      const messages = formatWebpackMessages(stats.toJson({}, true));
      if (messages.errors.length) {
        // Only keep the first error. Others are often indicative
        // of the same problem, but confuse the reader with noise.
        if (messages.errors.length > 1) {
          messages.errors.length = 1;
        }
        return reject(new Error(messages.errors.join('\n\n')));
      }
      if (
        process.env.CI &&
        (typeof process.env.CI !== 'string' ||
          process.env.CI.toLowerCase() !== 'false') &&
        messages.warnings.length
      ) {
        console.log(
          chalk.yellow(
            '\nTreating warnings as errors because process.env.CI = true.\n' +
              'Most CI servers set it automatically.\n'
          )
        );
        return reject(new Error(messages.warnings.join('\n\n')));
      }
      return resolve({
        stats,
        warnings: messages.warnings,
      });
    });
  }).then(
    ({ stats, warnings }) => {
      if (warnings.length) {
        console.log(chalk.yellow('Compiled with warnings.\n'));
        console.log(warnings.join('\n\n'));
        console.log(
          '\nSearch for the ' +
            chalk.underline(chalk.yellow('keywords')) +
            ' to learn more about each warning.'
        );
        console.log(
          'To ignore, add ' +
            chalk.cyan('// eslint-disable-next-line') +
            ' to the line before.\n'
        );
      } else {
        console.log(chalk.green('Compiled successfully.\n'));
      }
      console.log(`The ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))} folder is ready.`);
      console.log(`You may run it in ${chalk.cyan('node')} environment`);
      console.log();
      console.log(`  ${chalk.cyan('node')} ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))}`);
      console.log();
    },
    err => {
      console.log(chalk.red('Failed to compile.\n'));
      printBuildError(err);
      process.exit(1);
    }
  );
}
function buildServer() {
  console.log();
  console.log(`${chalk.cyan('SERVER-SIDE')}`);
  console.log('===========================================================');
  fs.emptyDirSync(paths.appServerBuild);
  console.log('Creating a server-side production build...');

  let compiler = webpack(serverlize(paths, config));
  return new Promise((resolve, reject) => {
    compiler.run((err, stats) => {
      if (err) {
        return reject(err);
      } 
      const messages = formatWebpackMessages(stats.toJson({}, true));
      if (messages.errors.length) {
        // Only keep the first error. Others are often indicative
        // of the same problem, but confuse the reader with noise.
        if (messages.errors.length > 1) {
          messages.errors.length = 1;
        }
        return reject(new Error(messages.errors.join('\n\n')));
      }
      if (
        process.env.CI &&
        (typeof process.env.CI !== 'string' ||
          process.env.CI.toLowerCase() !== 'false') &&
        messages.warnings.length
      ) {
        console.log(
          chalk.yellow(
            '\nTreating warnings as errors because process.env.CI = true.\n' +
              'Most CI servers set it automatically.\n'
          )
        );
        return reject(new Error(messages.warnings.join('\n\n')));
      }
      return resolve({
        stats,
        warnings: messages.warnings,
      });
    });
  }).then(
    ({ stats, warnings }) => {
      if (warnings.length) {
        console.log(chalk.yellow('Compiled with warnings.\n'));
        console.log(warnings.join('\n\n'));
        console.log(
          '\nSearch for the ' +
            chalk.underline(chalk.yellow('keywords')) +
            ' to learn more about each warning.'
        );
        console.log(
          'To ignore, add ' +
            chalk.cyan('// eslint-disable-next-line') +
            ' to the line before.\n'
        );
      } else {
        console.log(chalk.green('Compiled successfully.\n'));
      }
      console.log(`The ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))} folder is ready.`);
      console.log(`You may run it in ${chalk.cyan('node')} environment`);
      console.log();
      console.log(`  ${chalk.cyan('node')} ${chalk.cyan(path.relative(process.cwd(), paths.appServerBuild))}`);
      console.log();
    },
    err => {
      console.log(chalk.red('Failed to compile.\n'));
      printBuildError(err);
      process.exit(1);
    }
  );
}
function buildServer ( ) { console . log ( ) ; console . log ( ` ${ chalk . cyan ( 'SERVER-SIDE' ) } ` ) ; console . log ( '===========================================================' ) ; fs . emptyDirSync ( paths . appServerBuild ) ; console . log ( 'Creating a server-side production build...' ) ; let compiler = webpack ( serverlize ( paths , config ) ) ; return new Promise ( ( resolve , reject ) => { compiler . run ( ( err , stats ) => { if ( err ) { return reject ( err ) ; } const messages = formatWebpackMessages ( stats . toJson ( { } , true ) ) ; if ( messages . errors . length ) { // Only keep the first error. Others are often indicative // of the same problem, but confuse the reader with noise. if ( messages . errors . length > 1 ) { messages . errors . length = 1 ; } return reject ( new Error ( messages . errors . join ( '\n\n' ) ) ) ; } if ( process . env . CI && ( typeof process . env . CI !== 'string' || process . env . CI . toLowerCase ( ) !== 'false' ) && messages . warnings . length ) { console . log ( chalk . yellow ( '\nTreating warnings as errors because process.env.CI = true.\n' + 'Most CI servers set it automatically.\n' ) ) ; return reject ( new Error ( messages . warnings . join ( '\n\n' ) ) ) ; } return resolve ( { stats , warnings : messages . warnings , } ) ; } ) ; } ) . then ( ( { stats , warnings } ) => { if ( warnings . length ) { console . log ( chalk . yellow ( 'Compiled with warnings.\n' ) ) ; console . log ( warnings . join ( '\n\n' ) ) ; console . log ( '\nSearch for the ' + chalk . underline ( chalk . yellow ( 'keywords' ) ) + ' to learn more about each warning.' ) ; console . log ( 'To ignore, add ' + chalk . cyan ( '// eslint-disable-next-line' ) + ' to the line before.\n' ) ; } else { console . log ( chalk . green ( 'Compiled successfully.\n' ) ) ; } console . log ( ` ${ chalk . cyan ( path . relative ( process . cwd ( ) , paths . appServerBuild ) ) } ` ) ; console . log ( ` ${ chalk . cyan ( 'node' ) } ` ) ; console . log ( ) ; console . log ( ` ${ chalk . cyan ( 'node' ) } ${ chalk . cyan ( path . relative ( process . cwd ( ) , paths . appServerBuild ) ) } ` ) ; console . log ( ) ; } , err => { console . log ( chalk . red ( 'Failed to compile.\n' ) ) ; printBuildError ( err ) ; process . exit ( 1 ) ; } ) ; }
we can run the server-side build
we can run the server - side build