Global

Methods

filterFilesByType(files, type) → {Array.<File>}

Filter files by filetype. Use getFiles to retrieve the build files.
Parameters:
Name Type Description
files Array.<File> files to filter
type string file type, e.g. "js", "tsx", etc.
Since:
  • v2.2.0
Source:
Returns:
files filtered by file type
Type
Array.<File>

formatBytes(bytes, decimalsopt, binaryopt) → {string}

Format bytes to a human readable size.
Parameters:
Name Type Attributes Default Description
bytes number bytes to format
decimals number <optional>
2 decimal precision for rounding
binary boolean <optional>
false binary or decimal unit conversion
Since:
  • v2.1.0
Source:
Returns:
human readable file size with units
Type
string

(async) getBuildSizes(buildPath, bundleFileTypeopt) → {Promise.<BuildSizes>}

Determine metrics related to an application's build size.
Parameters:
Name Type Attributes Default Description
buildPath string path to the build directory
bundleFileType string <optional>
js file type of bundle, e.g. "js", "css", etc.
Source:
Returns:
build sizes
Type
Promise.<BuildSizes>

getFileSizeBrotli(filePath) → {Promise.<number>}

Compress a file using brotli and return the size.
Parameters:
Name Type Description
filePath string path of the file to compress
Since:
  • v3.0.0
Source:
Returns:
brotli-compressed byte size using the default zlib options
Type
Promise.<number>

getFileSizeGzip(filePath) → {Promise.<number>}

Compress a file using gzip and return the size.
Parameters:
Name Type Description
filePath string path of the file to compress
Since:
  • v3.0.0
Source:
Returns:
gzip-compressed byte size using the default zlib options
Type
Promise.<number>

(async) getFiles(parentDir) → {Promise.<Array.<File>>}

Find sizes of all files in a directory (recursive).
Parameters:
Name Type Description
parentDir string path to the directory containing the files
Since:
  • v2.1.0
Source:
Returns:
all files in the directory and subdirectories
Type
Promise.<Array.<File>>

(async) saveBuildSizes(buildSizes, outputPath)

Save the results from getBuildSizes to a CSV file. Useful for tracking build sizes over time, e.g., in a CI/CD pipeline.
Parameters:
Name Type Description
buildSizes BuildSizes build sizes that will be saved to CSV
outputPath string path of the output file, e.g. build/size.csv
Since:
  • v3.0.0
Source:

Type Definitions

BuildSizes

Information about an application's build sizes.
Type:
  • object
Properties:
Name Type Description
mainBundleName string name of the largest bundle size by type
mainBundleSize number byte size of the largest bundle file by type
mainBundleSizeGzip number gzip-compressed byte size of the main bundle file
mainBundleSizeBrotli number brotli-compressed byte size of the main bundle file
buildSize number byte size of all files in the build directory
buildSizeOnDisk number on-disk size in bytes of the build directory. Not available on Windows.
buildFileCount number count of all files in the build directory
Source:
See:

File

Information about a file.
Type:
  • object
Properties:
Name Type Description
name string file name with type
path string absolute file path
size string uncompressed file size
Source:
See: