Webpack Plugin

Last updated 9 days ago

Use our open source webpack plugin to report your webpack build information to our service.

The way we gather stats from your webpack builds is via our open source plugin. This plugin simply gathers some metadata about the build from source control, extracts the webpack stats object, and uploads the payload to our service for processing.

We always filter out your source from the stats object, and do not have access to your source code.

Install the webpack plugin

Once you have a project created, and a project_token in hand you can get your data flowing by installing and configuring our webpack plugin.

npm install --save @packtracker/webpack-plugin

Configure the plugin

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

const PacktrackerPlugin = require('@packtracker/webpack-plugin')
module.exports = {
plugins: [
new PacktrackerPlugin({
project_token: '<your packtracker project token>',
upload: true
})
]
}

If the plugin fails to upload your stats, it will not error out your build but it will log output signaling the failure. You can force it to fail your build by passing the fail_build configuration option or by setting the PT_FAIL_BUILD environment variable.

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.

Setting like this to upload from your local machine is a common first step in making sure you understand the process. Once your configuration is in place, run a build!

Once you see your stats are uploading and visible in the packtracker UI, it is common to take a few more steps to integrate it with your process:

Use the different configuration options to control when your stats get uploaded

As mentioned, the upload parameter ultimately is what tells the plugin to send us your build information. You can set this using an environment variable of your choosing. For example, if you have a CI service or solution, you could use it to only report your builds from that environment.

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

You could can also set any packtracker configuration option (including the project_token !) from an environment variable. In this case, if your environment has the PT_UPLOAD environment variable set to "true" the plugin will upload. See our complete list of options and environment variables.

Using automation for continuous feedback

While not a requirement, packtracker is most useful in the presence of build automation, whether that be a simple deployment script, a platform as a service, or a CI/CD service that runs with every commit. When automation is in place to handle uploading your statistics you gain a much more reliable mechanism for uploading and reporting. This also helps you take advantage of our GitHub Pull Request Checks.