Skip to main content
Customize bundling behavior without leaving the Extension.js workflow. Solve custom bundler needs without forking the default setup. Add loaders (file-type transforms), plugins (build-time extensions), and aliases (import shortcuts) directly. Extension.js builds with Rspack, a Rust-based JavaScript bundler (@rspack/core), and you can extend the generated configuration directly.

How it works

Create one of these files at project root:
  • extension.config.js
  • extension.config.mjs
  • extension.config.cjs
Use the config key to patch the generated bundler configuration.

config capabilities

Option 2: object merge

config can also be an object. Extension.js merges it into the base configuration.

Rspack-first, webpack-compatible

Extension.js is Rspack-native, but you can still use much of the webpack ecosystem.
  • The config type extends @rspack/core Configuration.
  • Many webpack loaders/plugins work through compatibility layers.
  • Some webpack internals/plugins are not 1:1 compatible with Rspack.
Example using a Rspack-native plugin:

Share a module between entries

Extension.js sets optimization.splitChunks to false on purpose. The manifest and each HTML page name one file per entry, so a module that three entries import is copied into three bundles. To keep one copy, load the module with import() from the pages that need it. Rspack emits one chunk for it, and every page fetches that chunk on demand from the extension origin. A cache group gives the chunk a stable name:
With this in place, await import("../shared/big") from the popup and from the options page both resolve to one emitted shared.js. Keep chunks at "async". A sync split moves code out of an entry file. The emitted HTML and the manifest reference only that entry file, so the page never loads the split chunk. The service worker cannot use dynamic import() and keeps its own copy of the module. A content script can share the chunk too, but it must expose the file through web_accessible_resources and import it through chrome.runtime.getURL. See Lazy loading for both rules.

When to use this

  • Add custom loaders/rules for project-specific file types.
  • Add plugins for compile-time transforms and diagnostics.
  • Override resolve aliases and module behavior not exposed by first-class Extension.js options.

Best practices

  • Prefer first-class options first: Use browser / commands configuration keys before low-level bundler overrides.
  • Patch minimally: Change only the pieces you need, then return the configuration.
  • Keep plugins Rspack-aware: Prefer Rspack-native plugins when available.
  • Verify on all targets: Test dev, start, preview, and build for your browser matrix after configuration changes.

Next steps