Back to Rspack

Other options

website/docs/en/config/other-options.mdx

2.0.14.3 KB
Original Source

import WebpackLicense from '@components/WebpackLicense'; import PropertyType from '@components/PropertyType'; import { ApiMeta } from '@components/ApiMeta';

<WebpackLicense from="https://webpack.js.org/configuration/other-options/" />

Other options

These are the remaining configuration options supported by rspack.

amd

<ApiMeta addedVersion="1.3.0" />
  • Type: false | Record<string, any>
  • Default: false

:::info Unlike webpack, where the default value of the amd option is {} (meaning AMD module dependency analysis is enabled by default), Rspack sets the default value of the amd option to false. This means AMD module dependency analysis is disabled by default in Rspack. This change was made because the usage of AMD modules is gradually decreasing. If your application requires it, you can enable this option by yourself. :::

Enable this option to support dependency analysis for AMD modules, which is helpful for compatibility with some older libraries written according to the AMD specification.

js
export default {
  amd: {}, // enable parsing AMD module dependencies
};

In addition, you can set the values of require.amd or define.amd through this configuration:

js
export default {
  amd: {
    jQuery: true, // `require.amd` and `define.amd` are set to `{ jQuery: true }`.
  },
};

bail

<PropertyType type="boolean" defaultValueList={[{ defaultValue: 'false' }]} />

Fail out on the first error instead of tolerating it. By default Rspack will log these errors in red in the terminal, as well as the browser console when using HMR, but continue bundling. To enable it:

js
export default {
  bail: true,
};

This will force Rspack to exit its bundling process.

dependencies

<PropertyType type="string[]" defaultValueList={[{ defaultValue: 'undefined' }]} />

A list of name defining all sibling configurations it depends on. Dependent configurations need to be compiled first.

In watch mode dependencies will invalidate the compiler when:

  1. the dependency has changed
  2. a dependency is currently compiling or invalid

Remember that current configuration will not compile until its dependencies are done.

js
export default [
  {
    name: 'client',
    target: 'web',
  },
  {
    name: 'server',
    target: 'node',
    dependencies: ['client'],
  },
];

ignoreWarnings

  • Type:
ts
type IgnoreWarnings = (
  | RegExp
  | {
      file?: RegExp;
      message?: RegExp;
      module?: RegExp;
    }
  | ((warning: WebpackError, compilation: Compilation) => boolean)
)[];
  • Default: undefined

Tells Rspack to suppress specific compilation warnings by matching their message, module, or file, or by using a custom function.

Use a RegExp to match the warning message:

js
export default {
  ignoreWarnings: [/warning from compiler/, /other warning/],
};

Use an object to match the warning via message, file, or module:

js
export default {
  ignoreWarnings: [
    { message: /warning from compiler/ },
    { file: /node_modules/ },
  ],
};

Use a function for full control. Return true to ignore the warning:

js
export default {
  ignoreWarnings: [
    (warning, compilation) => {
      return /warning from compiler/.test(warning.message || '');
    },
  ],
};

name

<PropertyType type="string" defaultValueList={[{ defaultValue: 'undefined' }]} />

Name of the configuration. Used when loading multiple configurations.

js
export default {
  name: 'admin-app',
};

loader

<PropertyType type="Record<string, any>" defaultValueList={[{ defaultValue: 'undefined' }]} />

Expose custom values into the loader context.

For example, you can define a new variable in the loader context:

js
export default {
  loader: {
    answer: 42,
  },
};

Then use this.answer to get its value in the loader:

js
export default function (source) {
  console.log(this.answer); // will log `42` here
  return source;
}

:::tip You can override properties in the loader context because Rspack copies all properties defined on the loader to the loader context. :::