Skip to content

Latest commit

 

History

History
150 lines (123 loc) · 4.2 KB

File metadata and controls

150 lines (123 loc) · 4.2 KB

Codecov by Sentry logo

Codecov Rspack Plugin

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!

Installation

Using npm:

npm install @codecov/rspack-plugin --save-dev

Using yarn:

yarn add @codecov/rspack-plugin --dev

Using pnpm:

pnpm add @codecov/rspack-plugin --save-dev

Public Repo Example - GitHub Actions

This 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",
    }),
  ],
};

Public Repo Example - Non-GitHub Actions

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>",
      },
    }),
  ],
};

Private Repo Example

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",
    }),
  ],
};

GitHub OIDC

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.