Skip to main content

Adapting RSPack config

Overview

Sometimes there are cases where the default configuration doesn't suffice and special requirements arise. For this special case we support with hooking directly into the build config of rspack.

info

For how the extension mechanism works internally (merge order, params, per-target exports), see Extending Rspack Configuration in the Architecture section.

Config

  1. create a file like rspack.extend.config.ts the name doesn't realy matter
  2. configure in archibald.json under the extendConfig property this name (relative to the root directory)
  3. adapt the config accordingly

Example rspack.extend.config.ts:

import { defineExtendConfig } from '@archibald/cli/build';

// adapts the client build
export const client = defineExtendConfig(({ params, config }) => {
const contenthash = params.isServe ? '' : '.[contenthash]';
const path = params.isServe ? 'http://localhost:3101/public/' : '/public/';

config.module.rules = [
...config.module.rules,
{
test: /\.(mp4)$/,
use: [
{
loader: require.resolve('file-loader'),
options: {
publicPath: path,
name: `[name]${contenthash}.[ext]`
}
}
]
}
];
return config;
});

// adapts the server build
export const node = defineExtendConfig(({ params, config }) => {
// adapt config to your need
config.context = './src';
return config
});

// adapts both client and server builds
export default defineExtendConfig(({ params, config }) => {
// adapt config to your need
config.context = './src';
return config
});