A Rspack plugin that provides bundle analysis support for Codecov.
Note
The plugin does not support code coverage, see our docs to set up coverage today!
Using npm:
npm install @codecov/rspack-plugin --save-devUsing yarn:
yarn add @codecov/rspack-plugin --devUsing pnpm:
pnpm add @codecov/rspack-plugin --save-devThis configuration will automatically upload the bundle analysis to Codecov for public repositories. When an internal PR is created it will use the Codecov token set in your secrets, and if running from a forked PR, it will use the tokenless setting automatically. For setups not using GitHub Actions see the following example. For private repositories see the following example.
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");
module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
uploadToken: process.env.CODECOV_TOKEN,
gitService: "github",
}),
],
};This setup is for public repositories that are not using GitHub Actions, this configuration will automatically upload the bundle analysis to Codecov. You will need to configure it similar to the GitHub Actions example, however you will need to provide a branch override, and ensure that it will pass the correct branch name, and with forks including the fork-owner i.e. fork-owner:branch.
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");
module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
uploadToken: process.env.CODECOV_TOKEN,
gitService: "github",
uploadOverrides: {
branch: "<branch value>",
},
}),
],
};This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov.
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");
module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
uploadToken: process.env.CODECOV_TOKEN,
gitService: "github",
}),
],
};For GitHub Actions users, you can use OIDC instead of a upload token. This is the recommended approach for GitHub Actions.
// rspack.config.js
const path = require("path");
const { codecovRspackPlugin } = require("@codecov/rspack-plugin");
module.exports = {
entry: "./src/index.js",
mode: "production",
output: {
filename: "main.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [
// Put the Codecov rspack plugin after all other plugins
codecovRspackPlugin({
enableBundleAnalysis: true,
bundleName: "example-rspack-bundle",
oidc: {
useGitHubOIDC: true,
},
}),
],
};See the full documentation for more details.