Back to Rspack

CaseSensitivePlugin

website/docs/en/plugins/webpack/case-sensitive-plugin.mdx

2.0.11.8 KB
Original Source

import { ApiMeta } from '@components/ApiMeta.tsx';

CaseSensitivePlugin

<ApiMeta addedVersion={'1.2.0'} />

Detect case sensitivity conflicts in referenced module names and emit warnings.

Different operating systems may handle case sensitivity in file systems differently. When code references module names that differ only in case, this can lead to unexpected errors during cross-platform compilation. This plugin helps to avoid such situations.

js
new rspack.CaseSensitivePlugin();

Register

js
import { rspack } from '@rspack/core';

export default {
  plugins: [new rspack.CaseSensitivePlugin()],
};

Example

Assume there is a utils.js file in the project:

text
src/
  ├── a.js
  ├── b.js
  └── utils.js

When importing utils.js in a.js and b.js, if the case sensitivity in the import path is inconsistent, the plugin will emit a warning.

js
import { helper } from './utils';
js
import { helper } from './Utils';

The warning is as follows:

bash
WARNING There are multiple modules with names that only differ in casing.

This warning indicates that there is a case sensitivity conflict in module names, ensuring that the same module is used with consistent case sensitivity in the project.

:::tip CaseSensitivePlugin is based on module identifiers rather than the file system to determine case sensitivity differences. :::

When the build output includes files whose names differ only in letter casing, the plugin will emit a warning to avoid potential conflicts on case-insensitive file systems.

bash
WARNING Prevent writing to file that only differs in casing or query string from already written file.
This will lead to a race-condition and corrupted files on case-insensitive file systems.
  - main.js
  - MAIN.js