|
| 1 | +<p align="center"> |
| 2 | + <a href="https://about.codecov.io" target="_blank"> |
| 3 | + <img src="https://about.codecov.io/wp-content/themes/codecov/assets/brand/sentry-cobranding/logos/codecov-by-sentry-logo.svg" alt="Codecov by Sentry logo" width="280" height="84"> |
| 4 | + </a> |
| 5 | +</p> |
| 6 | + |
| 7 | +# Codecov Rspack Plugin |
| 8 | + |
| 9 | +A Rspack plugin that provides bundle analysis support for Codecov. |
| 10 | + |
| 11 | +> [!NOTE] |
| 12 | +> The plugin does not support code coverage, see our [docs](https://docs.codecov.com/docs/quick-start) to set up coverage today! |
| 13 | +
|
| 14 | +## Installation |
| 15 | + |
| 16 | +Using npm: |
| 17 | + |
| 18 | +```bash |
| 19 | +npm install @codecov/rspack-plugin --save-dev |
| 20 | +``` |
| 21 | + |
| 22 | +Using yarn: |
| 23 | + |
| 24 | +```bash |
| 25 | +yarn add @codecov/rspack-plugin --dev |
| 26 | +``` |
| 27 | + |
| 28 | +Using pnpm: |
| 29 | + |
| 30 | +```bash |
| 31 | +pnpm add @codecov/rspack-plugin --save-dev |
| 32 | +``` |
| 33 | + |
| 34 | +## Public Repo Example - GitHub Actions |
| 35 | + |
| 36 | +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](#public-repo-example---non-github-actions). For private repositories see the following [example](#private-repo-example). |
| 37 | + |
| 38 | +```js |
| 39 | +// rspack.config.js |
| 40 | +const path = require("path"); |
| 41 | +const { codecovRspackPlugin } = require("@codecov/rspack-plugin"); |
| 42 | + |
| 43 | +module.exports = { |
| 44 | + entry: "./src/index.js", |
| 45 | + mode: "production", |
| 46 | + output: { |
| 47 | + filename: "main.js", |
| 48 | + path: path.resolve(__dirname, "dist"), |
| 49 | + }, |
| 50 | + plugins: [ |
| 51 | + // Put the Codecov rspack plugin after all other plugins |
| 52 | + codecovRspackPlugin({ |
| 53 | + enableBundleAnalysis: true, |
| 54 | + bundleName: "example-rspack-bundle", |
| 55 | + uploadToken: process.env.CODECOV_TOKEN, |
| 56 | + gitService: "github", |
| 57 | + }), |
| 58 | + ], |
| 59 | +}; |
| 60 | +``` |
| 61 | + |
| 62 | +## Public Repo Example - Non-GitHub Actions |
| 63 | + |
| 64 | +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`. |
| 65 | + |
| 66 | +```js |
| 67 | +// rspack.config.js |
| 68 | +const path = require("path"); |
| 69 | +const { codecovRspackPlugin } = require("@codecov/rspack-plugin"); |
| 70 | + |
| 71 | +module.exports = { |
| 72 | + entry: "./src/index.js", |
| 73 | + mode: "production", |
| 74 | + output: { |
| 75 | + filename: "main.js", |
| 76 | + path: path.resolve(__dirname, "dist"), |
| 77 | + }, |
| 78 | + plugins: [ |
| 79 | + // Put the Codecov rspack plugin after all other plugins |
| 80 | + codecovRspackPlugin({ |
| 81 | + enableBundleAnalysis: true, |
| 82 | + bundleName: "example-rspack-bundle", |
| 83 | + uploadToken: process.env.CODECOV_TOKEN, |
| 84 | + gitService: "github", |
| 85 | + uploadOverrides: { |
| 86 | + branch: "<branch value>", |
| 87 | + }, |
| 88 | + }), |
| 89 | + ], |
| 90 | +}; |
| 91 | +``` |
| 92 | + |
| 93 | +## Private Repo Example |
| 94 | + |
| 95 | +This is the required way to use the plugin for private repositories. This configuration will automatically upload the bundle analysis to Codecov. |
| 96 | + |
| 97 | +```js |
| 98 | +// rspack.config.js |
| 99 | +const path = require("path"); |
| 100 | +const { codecovRspackPlugin } = require("@codecov/rspack-plugin"); |
| 101 | + |
| 102 | +module.exports = { |
| 103 | + entry: "./src/index.js", |
| 104 | + mode: "production", |
| 105 | + output: { |
| 106 | + filename: "main.js", |
| 107 | + path: path.resolve(__dirname, "dist"), |
| 108 | + }, |
| 109 | + plugins: [ |
| 110 | + // Put the Codecov rspack plugin after all other plugins |
| 111 | + codecovRspackPlugin({ |
| 112 | + enableBundleAnalysis: true, |
| 113 | + bundleName: "example-rspack-bundle", |
| 114 | + uploadToken: process.env.CODECOV_TOKEN, |
| 115 | + gitService: "github", |
| 116 | + }), |
| 117 | + ], |
| 118 | +}; |
| 119 | +``` |
| 120 | + |
| 121 | +## GitHub OIDC |
| 122 | + |
| 123 | +For GitHub Actions users, you can use OIDC instead of a upload token. This is the recommended approach for GitHub Actions. |
| 124 | + |
| 125 | +```js |
| 126 | +// rspack.config.js |
| 127 | +const path = require("path"); |
| 128 | +const { codecovRspackPlugin } = require("@codecov/rspack-plugin"); |
| 129 | + |
| 130 | +module.exports = { |
| 131 | + entry: "./src/index.js", |
| 132 | + mode: "production", |
| 133 | + output: { |
| 134 | + filename: "main.js", |
| 135 | + path: path.resolve(__dirname, "dist"), |
| 136 | + }, |
| 137 | + plugins: [ |
| 138 | + // Put the Codecov rspack plugin after all other plugins |
| 139 | + codecovRspackPlugin({ |
| 140 | + enableBundleAnalysis: true, |
| 141 | + bundleName: "example-rspack-bundle", |
| 142 | + oidc: { |
| 143 | + useGitHubOIDC: true, |
| 144 | + }, |
| 145 | + }), |
| 146 | + ], |
| 147 | +}; |
| 148 | +``` |
| 149 | + |
| 150 | +See the [full documentation](https://docs.codecov.com/docs/bundle-analysis) for more details. |
0 commit comments