{"id":17818,"library":"monosize-bundler-rspack","title":"monosize Rspack Bundler Plugin","description":"monosize-bundler-rspack is a specialized plugin for the `monosize` tool, designed to integrate Rspack as the underlying bundler for comprehensive JavaScript bundle size analysis. It allows developers to harness the high performance of Rspack for evaluating bundle sizes within large-scale monorepos or projects optimized for `monosize`. Currently at version 0.2.1, it is an actively developed component within the broader Microsoft `monosize` ecosystem. While exact release cadences are not strictly defined for this plugin, its early version number indicates ongoing development and potential for rapid evolution. A key differentiator is its default 'batch build mode,' which significantly enhances build speed (8-14x faster in typical scenarios) compared to sequential bundling, making it exceptionally well-suited for efficient monorepo size optimization. The plugin also provides an API to customize the underlying rsbuild configuration, offering flexibility for intricate build requirements.","status":"active","version":"0.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/microsoft/monosize","tags":["javascript","typescript"],"install":[{"cmd":"npm install monosize-bundler-rspack","lang":"bash","label":"npm"},{"cmd":"yarn add monosize-bundler-rspack","lang":"bash","label":"yarn"},{"cmd":"pnpm add monosize-bundler-rspack","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a plugin for monosize and requires it to be installed in the project for any functionality.","package":"monosize","optional":false},{"reason":"Internal dependency for configuring Rspack builds. May not be directly installed by the user but is critical to the bundler's operation.","package":"@rsbuild/core","optional":false}],"imports":[{"note":"This plugin expects an ES module environment, typically used within a `monosize.config.mjs` file.","wrong":"const rspackBundler = require('monosize-bundler-rspack');","symbol":"rspackBundler","correct":"import rspackBundler from 'monosize-bundler-rspack';"},{"note":"Import for TypeScript type definitions when customizing the rsbuild configuration.","symbol":"RspackBundlerConfig","correct":"import type { RspackBundlerConfig } from 'monosize-bundler-rspack';"},{"note":"Type for the callback function passed to `rspackBundler` for configuration customization.","symbol":"CustomizeConfigCallback","correct":"import type { CustomizeConfigCallback } from 'monosize-bundler-rspack';"}],"quickstart":{"code":"/* monosize.config.mjs */\nimport rspackBundler from 'monosize-bundler-rspack';\n\n/**\n * @type {import('monosize').MonosizeConfig}\n */\nexport default {\n  // Define your workspace roots for monosize to scan\n  workspaces: [\n    'packages/*',\n    'apps/*'\n  ],\n  // Specify fixtures (entry points) for size measurement\n  fixtures: {\n    'my-component': 'packages/my-component/src/index.ts',\n    'my-util': 'packages/my-util/src/index.ts'\n  },\n  // Integrate the Rspack bundler plugin\n  bundler: rspackBundler(config => {\n    // Example: Customize Rspack's resolve alias for specific packages\n    config.resolve ??= {};\n    config.resolve.alias = {\n      ...config.resolve.alias,\n      'some-internal-lib': 'libs/some-internal-lib/dist/esm/index.js'\n    };\n    // Example: Add a new rule for handling SVG files\n    config.module?.rules?.push({\n        test: /\\.svg$/,\n        type: 'asset/resource'\n    });\n    return config;\n  }),\n  // Other monosize configurations...\n  output: {\n    dir: './monosize-results',\n    filename: 'report.json'\n  }\n};\n\n/* Example of how to run this config in your package.json */\n// \"scripts\": {\n//   \"measure-size\": \"monosize measure\"\n// }","lang":"typescript","description":"This quickstart demonstrates configuring `monosize.config.mjs` to use `monosize-bundler-rspack` as the bundler, including examples of customizing the underlying rsbuild configuration for aliases and module rules."},"warnings":[{"fix":"Always check the GitHub repository's release notes or changelog before upgrading for versions below 1.0.0.","message":"As a pre-1.0 package (current version 0.2.1), `monosize-bundler-rspack` may introduce breaking changes in minor or even patch versions. Developers should review release notes carefully when upgrading.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"To use sequential mode, run `monosize measure --build-mode=sequential`. This builds one fixture at a time, which can be helpful for debugging build-specific problems.","message":"By default, `monosize` runs in 'batch build mode' when using this bundler, which is significantly faster. However, this can sometimes obscure issues related to individual builds. If you suspect an issue with a specific fixture's build, you might need to switch to sequential mode.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"When customizing the configuration, make incremental changes and thoroughly test the output. Refer to the rsbuild documentation for valid configuration options. Utilize `console.log(config)` within the callback to inspect the default configuration before modification.","message":"The `rspackBundler` function accepts a callback to customize the rsbuild configuration. Incorrect modifications to this configuration, especially if they conflict with `monosize`'s internal bundling assumptions, can lead to incorrect size measurements or build failures.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure the package is installed as a dev dependency: `npm install --save-dev monosize-bundler-rspack` or `yarn add --dev monosize-bundler-rspack`.","cause":"The `monosize-bundler-rspack` package has not been installed, or the path in the import statement is incorrect.","error":"Error: Cannot find module 'monosize-bundler-rspack' from 'monosize.config.mjs'"},{"fix":"Ensure your `monosize.config.mjs` uses `import rspackBundler from 'monosize-bundler-rspack';` and not `const rspackBundler = require(...)` or `import { rspackBundler } from '...'`. Also verify the file extension is `.mjs`.","cause":"This usually indicates a CommonJS `require` call was used in an ES module context (`.mjs` file) or a named import was attempted for a default export.","error":"TypeError: rspackBundler is not a function"},{"fix":"Carefully review the Rspack error messages for specifics. Debug your `monosize.config.mjs` customization by commenting out changes, and ensure all source files and their dependencies are correctly resolved and valid.","cause":"The customized rsbuild configuration is invalid, or there's an issue with one of the source files being bundled (e.g., missing dependencies, syntax errors).","error":"rsbuild build failed: [detailed Rspack error messages]"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}