### Package.json Configuration Example Source: https://bundlewatch.io/guide/using-a-config-file Configure Bundlewatch by adding a 'bundlewatch' key to your package.json. Specify files to track and their maximum allowed size. ```json { "name": "my package name", "version": "0.0.1", "bundlewatch": { "files": [ { "path": "myfolder/*.js", "maxSize": "100kB" } ] } } ``` -------------------------------- ### BundleWatch CLI Examples Source: https://bundlewatch.io/reference/cli Demonstrates various ways to use BundleWatch from the command line, including reading configuration from package.json, a specified file, or using direct command-line arguments. ```bash $ bundlewatch ``` ```bash $ bundlewatch --config internals/bundlewatch.config.js ``` ```bash $ bundlewatch --max-size 100KB ./src/*.js /lib/*.js ``` -------------------------------- ### Install BundleWatch with Yarn Source: https://bundlewatch.io/guide/getting-started Use this command to install BundleWatch as a development dependency using Yarn. ```bash yarn add bundlewatch --dev ``` -------------------------------- ### Install BundleWatch with npm Source: https://bundlewatch.io/guide/getting-started Use this command to install BundleWatch as a development dependency using npm. ```bash npm install bundlewatch --save-dev ``` -------------------------------- ### Run Bundlewatch on Built Assets Source: https://bundlewatch.io/guide/using-bundlewatch Execute Bundlewatch from your terminal to get immediate feedback on asset sizes. Specify the maximum allowed size and the path to your build files. ```bash yarn run bundlewatch --max-size 100kb ./webpack-build/*.js ``` -------------------------------- ### NodeJS API Usage Example Source: https://bundlewatch.io/reference/nodejs Import and use the bundlewatch API to analyze files. Configure file paths, maximum sizes, compression, and CI/CD integration. The output includes detailed results and a summary status. ```javascript import bundlewatch from 'bundlewatch' const results = await bundlewatch({ files: [{ path: './myfolder/*.js', maxSize: '100kb', compression: 'none', }], bundlewatchServiceHost: 'https://service.bundlewatch.io', // Can be a custom service ci: { githubAccessToken: ciEnv.githubAccessToken, repoOwner: ciEnv.repoOwner, repoName: ciEnv.repoName, repoCurrentBranch: ciEnv.repoCurrentBranch, repoBranchBase: ciEnv.repoBranchBase || 'master', // Branch PR is being merged into commitSha: ciEnv.commitSha, trackBranches: ['master', 'develop'], }, defaultCompression: 'gzip', }) console.log(results) // Outputs: { status: 'fail', fullResults: [ { filePath: './myfolder/test-file-1.jpg', message: '30.71KB < 100KB (gzip)', status: 'pass', size: 31448, baseBranchSize: 0, maxSize: 102400 }, { filePath: './myfolder/test-file-2.jpg', message: '198.6KB > 100KB (gzip)', status: 'fail', size: 203368, baseBranchSize: 0, maxSize: 102400 } ], summary: 'maxSize check failed', url: 'https://ja2r7.app.goo.gl/FJR3Rx1EdC1QjAii1' } // Status strings can also be accessed from the api // import { STATUSES } from 'bundlewatch' console.log(result.status === STATUES.FAIL) ``` -------------------------------- ### Display BundleWatch Help Source: https://bundlewatch.io/reference/cli View available command-line options and usage information for BundleWatch. ```bash yarn bundlewatch --help ``` -------------------------------- ### Specify Custom Config File Source: https://bundlewatch.io/guide/using-a-config-file Use the --config flag to point Bundlewatch to a custom configuration file. ```bash bundlewatch --config .bundlewatch.config.js ``` -------------------------------- ### Configure Custom Bundlewatch Service Host Source: https://bundlewatch.io/guide/using-a-custom-server Update your Bundlewatch configuration to point to your custom server's host URL. Ensure your custom service is running before setting this option. ```javascript module.exports = { files: [...], bundlewatchServiceHost: 'https://my-bundlewatch-service.example.com', } ``` -------------------------------- ### Define BundleWatch configuration Source: https://bundlewatch.io/reference/configuration The primary configuration object exported from myconfig.js, requiring a files array. ```javascript const bundlewatchConfig = { files: [ { path: "./myfolder/*.js", maxSize: "100kb", compression: "none", }, ], normalizeFilenames: /^.+?(\..+?)\.\w+$/, bundlewatchServiceHost: "https://service.bundlewatch.io", // Can be a custom service ci: { githubAccessToken: ciEnv.githubAccessToken, repoOwner: ciEnv.repoOwner, repoName: ciEnv.repoName, repoCurrentBranch: ciEnv.repoCurrentBranch, repoBranchBase: ciEnv.repoBranchBase || "master", // Branch PR is being merged into commitSha: ciEnv.commitSha, trackBranches: ["master", "develop"], }, defaultCompression: "gzip", }; module.exports = bundlewatchConfig; ``` -------------------------------- ### Configure CI integration Source: https://bundlewatch.io/reference/configuration The ci object enables core features by providing repository and authentication details. ```javascript { githubAccessToken: ciEnv.githubAccessToken, repoOwner: ciEnv.repoOwner, repoName: ciEnv.repoName, repoCurrentBranch: ciEnv.repoCurrentBranch, repoBranchBase: ciEnv.repoBranchBase || 'master', // Branch PR is being merged into commitSha: ciEnv.commitSha, trackBranches: ['master', 'develop'], } ``` -------------------------------- ### Configure BundleWatch to Track Multiple Branches Source: https://bundlewatch.io/guide/diffing-against-branches-other-than-master Add the 'trackBranches' option to your Bundlewatch configuration in 'package.json' to specify which branches should be compared against. ```json { "bundlewatch": { "files": [ { "path": "myfolder/*.js", "maxSize": "100kB" } ], "ci": { "trackBranches": ["master", "develop", "staging"] } } } ``` -------------------------------- ### Configure file tracking Source: https://bundlewatch.io/reference/configuration Individual file objects within the files array define the path, size limits, and compression method. ```javascript { path: './myfolder/*.js', // Required maxSize: '100kb', compression: 'none', } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.