Using a config file
Create bundlewatch.config.mjs in your project root, then run:
npx bundlewatchA standalone config file is the recommended setup. BundleWatch discovers the filenames shown below automatically; see config discovery for the search order.
/** @type {import('bundlewatch').BundlewatchConfig} */
export default {
files: [
{
path: './dist/*.js',
maxSize: '100kB',
},
],
}import type { BundlewatchConfig } from 'bundlewatch'
export default {
files: [
{
path: './dist/*.js',
maxSize: '100kB',
},
],
} satisfies BundlewatchConfigmodule.exports = {
files: [
{
path: './dist/*.js',
maxSize: '100kB',
},
],
}{
"files": [
{
"path": "./dist/*.js",
"maxSize": "100kB"
}
]
}- Config files can be
.json,.js,.cjsor.mjs, or.ts,.mtsor.ctson Node.js 22.18 and later, which run TypeScript natively.--configpaths are resolved from the current directory; absolute paths work too. - The
BundlewatchConfigtype gives your editor completion and checks for every option. - In TypeScript, prefer
.mts: Node.js loads it as an ES module in any package. A.tsfile works too, but in a package without"type": "module", Node.js prints a warning before loading it. - A JavaScript or TypeScript config can also have only named exports, such as
export const files = [...], instead of a default export. - A JavaScript config can set options that JSON can't, such as a
RegExpfornormalizeFilenames, or values computed from environment variables.
Your configuration is merged with the defaults. If more than one source is present, see Where configuration comes from.
You can also supply the config directly to the Node.js API.
Config discovery
Without command-line globs or --config, BundleWatch searches from the current directory upward. In each directory it checks these filenames, in order:
bundlewatch.config.mjsbundlewatch.config.jsbundlewatch.config.cjsbundlewatch.config.mtsbundlewatch.config.tsbundlewatch.config.ctsbundlewatch.config.json
The first file found wins. The search includes the directory containing the nearest package.json, then stops. If no config file is found, BundleWatch reads that package's bundlewatch key. It does not search beyond that package, even if the key is missing. Without a package.json, it searches up to the filesystem root.
A file that cannot be loaded, or whose configuration is invalid, fails the run; BundleWatch does not fall back to another file or to package.json. File globs remain relative to the directory where you run BundleWatch, even when the config is in a parent directory.
For a custom filename or location, use --config. This overrides discovery and can select a shared config outside the current package:
npx bundlewatch --config ../shared/bundlewatch.config.mjsAlternative: package.json
You can also keep configuration under the bundlewatch key in package.json:
{
"bundlewatch": {
"files": [
{
"path": "./dist/*.js",
"maxSize": "100kB"
}
]
}
}Run npx bundlewatch to read this configuration when no config file is discovered. Command-line globs, --config, and discovered config files take precedence over this key. In a monorepo, keep the key in the package’s own package.json, or use --config to select a shared file explicitly.