How to use the react-dev-utils/FileSizeReporter.measureFileSizesBeforeBuild function in react-dev-utils

To help you get started, we’ve selected a few react-dev-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FallOutChonny / react-starter-boilerplate / scripts / build.js View on Github external
measureFileSizesBeforeBuild,
  printFileSizesAfterBuild
} = require('react-dev-utils/FileSizeReporter');
const { compile, createConfig } = require('../config/webpack');
const paths = require('../config/paths');

const useYarn = fs.existsSync(paths.yarnLockFile);

// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appIndexJs, paths.appServerIndexJs])) {
  process.exit(1);
}

// First, read the current file sizes in build directory.
// This lets us display how much they changed later.
measureFileSizesBeforeBuild(paths.appBuild)
  .then(previousFileSizes => {
    // Remove all content but keep the directory so that
    // if you're in it, you don't end up in Trash
    fs.emptyDirSync(paths.appBuild);
    // Merge with the public folder
    copyPublicFolder();
    // Start the webpack build
    return build(previousFileSizes);
  })
  .then(
    ({ stats, previousFileSizes, warnings }) => {
      if (warnings.length) {
        console.log(chalk.yellow('Compiled with warnings.\n'));
        console.log(warnings.join('\n\n'));
        console.log(
          '\nSearch for the ' +
github nusmodifications / nusmods / www / scripts / build.js View on Github external
} catch (err) {
    printErrors('Failed to compile.', [err]);
    process.exit(1);
  }
}

// Write commit hash into `commit-hash.txt` for reference during deployment.
function writeCommitHash() {
  const { commitHash } = parts.appVersion();
  // Sync filename with `scripts/promote-staging.sh`.
  fs.writeFileSync(path.join(parts.PATHS.build, 'commit-hash.txt'), `${commitHash.slice(0, 7)}\n`);
}

// First, read the current file sizes in build directory.
// This lets us display how much they changed later.
measureFileSizesBeforeBuild(parts.PATHS.build)
  .then((previousFileSizes) => build(previousFileSizes))
  .then(async () => {
    try {
      await createTag();
    } catch (e) {
      // Swallow error
    }
  })
  .then(writeCommitHash);
github nusmodifications / nusmods / v3 / scripts / build.js View on Github external
console.log(`The ${chalk.cyan(parts.PATHS.build)} folder is ready to be deployed.`);

    callback();
  });
}

// Write commit hash into `commit-hash.txt` for reference during deployment.
function writeCommitHash() {
  const { commitHash } = parts.appVersion();
  // Sync filename with `scripts/promote-staging.sh`.
  fs.writeFileSync(path.join(parts.PATHS.build, 'commit-hash.txt'), `${commitHash.slice(0, 7)}\n`);
}

// First, read the current file sizes in build directory.
// This lets us display how much they changed later.
measureFileSizesBeforeBuild(parts.PATHS.build)
  .then((previousFileSizes) => new Promise((resolve) => build(previousFileSizes, resolve)))
  .then(writeCommitHash);
github imodeljs / imodeljs / tools / webpack / scripts / build.js View on Github external
async function prepFrontendBuild() {
    if (skipFrontend)
      return;

    // First, read the current file sizes in build directory.
    // This lets us display how much they changed later.
    const previousFileSizes = await measureFileSizesBeforeBuild(paths.appLibPublic);

    // Remove all content but keep the directory so that
    // if you're in it, you don't end up in Trash
    await fs.emptyDir(paths.appLibPublic);

    // Merge with the public folder
    await fs.copy(paths.appPublic, paths.appLibPublic, {
      dereference: true,
      filter: file => file !== paths.appHtml,
    });

    return previousFileSizes;
  }
github cullenjett / react-ssr-boilerplate / scripts / build.js View on Github external
} = require('react-dev-utils/FileSizeReporter');

const createConfig = require('../config/webpackConfigFactory');
const serverConfig = require('../config/webpack.server.prod');
const clientConfig = createConfig('production');

process.on('unhandledRejection', err => {
  throw err;
});

const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;

const resolvePath = relativePath => path.resolve(__dirname, relativePath);

measureFileSizesBeforeBuild(resolvePath('../build'))
  .then(previousFileSizes => {
    fs.emptyDirSync(resolvePath('../build'));
    return build(previousFileSizes);
  })
  .then(
    result => printResult(result),
    err => {
      console.log(chalk.red('Failed to compile.\n'));
      console.log((err.message || err) + '\n');
      process.exit(1);
    }
  );

function build(previousFileSizes) {
  console.log(chalk.blue('\n\tCreating an optimized production build...\n'));
github wix / pro-gallery / packages / ssr-simulator / scripts / build.js View on Github external
} = require('react-dev-utils/FileSizeReporter');

const createConfig = require('../config/webpackConfigFactory');
const serverConfig = require('../config/webpack.server.prod');
const clientConfig = createConfig('production');

process.on('unhandledRejection', err => {
  throw err;
});

const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;

const resolvePath = relativePath => path.resolve(__dirname, relativePath);

measureFileSizesBeforeBuild(resolvePath('../build'))
  .then(previousFileSizes => {
    fs.emptyDirSync(resolvePath('../build'));
    return build(previousFileSizes);
  })
  .then(
    result => printResult(result),
    err => {
      console.log(chalk.red('Failed to compile.\n'));
      console.log((err.message || err) + '\n');
      process.exit(1);
    }
  );

function build(previousFileSizes) {
  console.log(chalk.blue('\n\tCreating an optimized production build...\n'));
github dexdexplatform / dexdex-mono / packages / widget / scripts / build.js View on Github external
async function run() {
  try {
    const previousFileSizes = await measureFileSizesBeforeBuild(paths.appBuild);
    fs.emptyDirSync(paths.appBuild);
    const { stats, warnings } = await build();
    copyPublicFolder();
    printSummary(previousFileSizes, stats, warnings);
  } catch (err) {
    console.log(chalk.red('Failed to compile.\n'));
    printBuildError(err);
    throw err;
  }
}
github sensu / sensu-go / dashboard / scripts / build.js View on Github external
import webpack from "webpack";

import "./exceptionHandler";
import assertEnv from "./assertEnv";
import getConfig from "../config/webpack.config";

process.env.NODE_ENV = process.env.NODE_ENV || "production";

assertEnv();

const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;

const config = getConfig();

FileSizeReporter.measureFileSizesBeforeBuild(config.output.path).then(
  previousFileSizes => {
    console.log(`Starting webpack compiler in ${config.mode} mode`);

    const compiler = webpack(config);

    compiler.run((error, stats) => {
      if (error) {
        throw error;
      }

      const messages = formatWebpackMessages(stats.toJson({}, true));

      if (messages.errors.length) {
        throw new Error(messages.errors[0]);
      }
github ZachGawlik / webpack-stats-diff-plugin / src / index.js View on Github external
compareWithBuildOutput() {
    if (Object.keys(this.sizesBeforeBuild).length > 0) {
      getBuildFolderSizes(this.buildRoot).then(({ sizes }) => {
        printStatsDiff(
          getAssetsDiff(this.sizesBeforeBuild, sizes, this.config),
          null,
          2
        );
      });
    }
  }
}