Home

Awesome

<p align="center"> <img width="125" height="125" src="https://user-images.githubusercontent.com/401520/46344408-a24f2780-c606-11e8-991b-579047b2cf95.png"> </p>

packtracker.io webpack plugin

Build Status Coverage Status Codacy Badge JavaScript Style Guide

This plugin is designed to upload your webpack build stats to the packtracker.io service.

Installation

Once you have your project created on packtracker.io, and a project_token in hand, you can get your data flowing by installing and configuring this plugin.

npm install --save-dev @packtracker/webpack-plugin

Usage

Webpack Plugin

In your webpack configuration include the plugin (along with your project token).

If the plugin fails to upload your stats, it will not error out your build but it will log output signaling the failure.

const PacktrackerPlugin = require('@packtracker/webpack-plugin')

module.exports = {
  plugins: [
    new PacktrackerPlugin({
      project_token: '<your packtracker project token>',
      upload: true
    })
  ]
}

The upload option above tells the plugin whether or not to upload your build stats when running webpack. By default, this option is set to false to prevent accidental uploading from your local machine. If the upload option is left false, the plugin will do nothing.

Once you see your stats are uploading, it is common to only upload when building your assets in a CI environment or during deployment. You can also omit this option altogether, and set the PT_UPLOAD environment variable on a per run basis to control the upload of your stats.

For example

const PacktrackerPlugin = require('@packtracker/webpack-plugin')

module.exports = {
  plugins: [
    new PacktrackerPlugin({
      project_token: '<your packtracker project token>',
      upload: process.env.CI === 'true'
    })
  ]
}

CLI

In addition to the primary use case of uploading as part of your build process via our webpack plugin, we also have a command line uploader that works well with tools like create-react-app that allow you to export your stats, but don't allow full plugin configuration.

The only caveat to using the CLI is that you must use environment variables to configure your stat reporting (most importantly PT_PROJECT_TOKEN).

Example with create-react-app

In your package.json you can add a run script like the following

{
  "scripts": {
    "packtracker": "react-scripts build --stats && packtracker-upload --stats=build/bundle-stats.json"
  }
}

The only additional parameter you can pass via the CLI is the --output-path=<path to webpack output>, if it is not passed we assume it is the directory that contains your bundle stats file.

Then running npm run packtracker should upload your stats to our service

Options

All of the options, available to the plugin can be set via argument to the plugin, environment variable, or allowed to query your local git repository.

Here is a listing of the plugin options, environment variable counterparts, and a description.

OptionEnv VariableDescription
project_tokenPT_PROJECT_TOKENThe project token for your packtracker.io project (required)
fail_buildPT_FAIL_BUILDFail the build if the stat upload fails (default: false)
branchPT_BRANCHBranch of the commit <br> (default: git rev-parse --abbrev-ref HEAD)
authorPT_AUTHORCommitter's email (default: git log --format="%aE" -n 1 HEAD)
messagePT_MESSAGEThe commit message (default: git log --format="%B" -n 1 HEAD)
commitPT_COMMITThe commit sha (default: git rev-parse HEAD)
committed_atPT_COMMITTED_ATUnix timestamp (ms) of the commit <br> (default: git log --format="%ct" -n 1 HEAD)
prior_commitPT_PRIOR_COMMITThe previous commit sha (default: git rev-parse HEAD^)
exclude_assetsPT_EXCLUDE_ASSETSMirrors the excludeAssets configuration in the webpack stats config (only available to webpack version 3.5.0+) (compiled as RegExp when provided via environment variable)

You can find more documentation about the packtracker.io service in general at https://docs.packtracker.io