> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Module parser

`module.parser` controls how Rspack reads modules after they are resolved. It affects how dependencies are collected, how syntax such as `import.meta` and dynamic `import()` is interpreted, and other parsing behavior for each module type.

## parser

- **Type:** `Object`
- **Default:** `{}`

Use `module.parser` to define parser options for each module type.

Available parser option groups:

- `asset`: [Asset parser options](#asset)
- `javascript`, `javascript/auto`, `javascript/dynamic`, `javascript/esm`: [JavaScript parser options](#javascript)
- `json`: [JSON parser options](#json)
- `css`, `css/auto`, `css/global`, `css/module`: [CSS parser options](#cssauto)

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      // Parser options for asset modules
      asset: {
        dataUrlCondition: {
          maxSize: 16192,
        },
      },
      // Parser options for javascript modules
      javascript: {
        dynamicImportMode: 'lazy',
        dynamicImportPrefetch: false,
        dynamicImportPreload: false,
        url: true,
        importMeta: true,
      },
      // Parser options for CSS modules
      css: {
        namedExports: true,
      },
      // Parser options for css/auto modules
      'css/auto': {
        namedExports: true,
      },
      // Parser options for css/module modules
      'css/module': {
        namedExports: true,
      },
    },
  },
};
```

### asset

Parser options for `asset` modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      asset: {
        // options
      },
    },
  },
};
```

### asset.dataUrlCondition

- **Type:** `{ maxSize: number }`
- **Default:** `{ maxSize: 8096 }`

If the module size is less than or equal to `maxSize`, then the module will be Base64 encoded, otherwise a file will be created. This option can be used only for [Asset modules](/guide/features/asset-module.md).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      asset: {
        dataUrlCondition: {
          // Modules' size smaller than or equal to 4KB will be Base64 encoded.
          maxSize: 4 * 1024,
        },
      },
    },
  },
};
```

### javascript

Parser options for `javascript` modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        // options
      },
    },
  },
};
```

### javascript.commonjsMagicComments


- Type: `boolean`
- Default:`false`



[Added in v1.5.6](https://github.com/web-infra-dev/rspack/releases/tag/v1.5.6)

Enable [Magic comments](/api/runtime-api/module-methods.md#magic-comments) support for CommonJS.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        commonjsMagicComments: true,
      },
    },
  },
};
```

Note that only the `rspackIgnore` and `webpackIgnore` comments are supported at the moment.

:::tip
Since Rspack 2.1.0, prefer `rspackIgnore`. `webpackIgnore` remains supported for compatibility.
:::

```js
const x = require(/* rspackIgnore: true */ 'x');
const y = require(/* webpackIgnore: true */ 'y');
```

### javascript.dynamicImportMode


- Type: `'lazy' | 'eager' | 'weak' | 'lazy-once'`
- Default:`'lazy'`


Specifies global mode for dynamic import, see [`rspackMode`](/api/runtime-api/module-methods.md#rspackmode) for more details.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        dynamicImportMode: 'eager',
      },
    },
  },
};
```

### javascript.dynamicImportPrefetch


- Type: `boolean | number`
- Default:`false`


Specifies global prefetch for dynamic import, see [`rspackPrefetch`](/api/runtime-api/module-methods.md#rspackprefetch) for more details.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        dynamicImportPrefetch: true,
      },
    },
  },
};
```

### javascript.dynamicImportPreload


- Type: `boolean | number`
- Default:`false`


Specifies global preload for dynamic import, see [`rspackPreload`](/api/runtime-api/module-methods.md#rspackpreload) for more details.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        dynamicImportPreload: true,
      },
    },
  },
};
```

### javascript.dynamicImportFetchPriority


- Type: `'low' | 'high' | 'auto'`
- Default:`'auto'`


Specifies global `fetchPriority` for dynamic import, see [`rspackFetchPriority`](/api/runtime-api/module-methods.md#rspackfetchpriority) for more details.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        dynamicImportFetchPriority: 'high',
      },
    },
  },
};
```

### javascript.url


- Type: `true | false | 'relative' | 'new-url-relative'`
- Default:`true`


Enable parsing of `new URL()` syntax.

- `true`: Generate absolute URLs that include the root URL (default behavior).
- `'relative'`: Generate relative URLs without the root URL.
- `'new-url-relative'`: Generate static relative URLs that are replaced at compile-time with the correct public path.

When using `'new-url-relative'`, Rspack generates relative URLs that will be replaced at compile-time with the correct public path:

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        url: 'new-url-relative',
      },
    },
  },
};
```

```js
new URL('./icon.svg', import.meta.url);

// would become 👇
new URL('./icon[hash].svg', import.meta.url);
```

When using `'relative'`, Rspack generates runtime code to calculate relative URLs for `new URL()` syntax, i.e., there's no base URL included in the result URL:

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        url: 'relative',
      },
    },
  },
};
```

```html
<!-- with 'relative' -->
<img src="icon.svg" />

<!-- without 'relative' -->
<img src="file:///path/to/project/dist/icon.svg" />
```

### javascript.exprContextCritical


- Type: `boolean | undefined`
- Default:`true`


Enable warnings for full dynamic dependencies (`import(variable)`).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        exprContextCritical: false,
      },
    },
  },
};
```

### javascript.wrappedContextCritical


- Type: `boolean | undefined`
- Default:`false`


Enable warnings for partial dynamic dependencies (`import("./path/to/" + variable)`).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        wrappedContextCritical: false,
      },
    },
  },
};
```

### javascript.unknownContextCritical


- Type: `boolean | undefined`
- Default:`true`


Enable warnings when using the `require` function in a non-statically-analyzable way (`require(variable)`).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        unknownContextCritical: false,
      },
    },
  },
};
```

### javascript.wrappedContextRegExp


- Type: `RegExp | undefined`
- Default:`/.*/`


Set a regular expression to match wrapped dynamic dependencies.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        wrappedContextRegExp: /\.js$/,
      },
    },
  },
};
```

### javascript.importMeta

- **Type:** `boolean | 'preserve-unknown' | ImportMetaParserOptions`
- **Default:** When using [ESM output](/guide/features/esm.md), the default value is `'preserve-unknown'`; otherwise, it is `true`

Control whether Rspack parses and replaces `import.meta` in source code. Available values:

- `"preserve-unknown"`: [Known `import.meta` properties](/api/runtime-api/module-variables.md#import-meta) are statically analyzed at compile-time, other properties are preserved and evaluated at runtime.
- `true`: All `import.meta` properties are statically analyzed at compile-time.
- `false`: All `import.meta` properties are evaluated at runtime.
- `ImportMetaParserOptions`: Configure each known `import.meta` property independently. Properties set to `false` are preserved for runtime evaluation, while omitted properties keep the default enabled behavior. Unknown `import.meta` properties are preserved.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        importMeta: false,
      },
    },
  },
};
```

The object form supports the following keys:

- Webpack-compatible keys: `dirname`, `filename`, `main`, `url`, `webpack`, and `webpackContext`.
- Rspack-specific keys: `glob`, `resolve`, `rspackBaseUri`, `rspackHash`, `rspackInitSharing`, `rspackNonce`, `rspackPublicPath`, `rspackRsc`, `rspackShareScopes`, `rspackUniqueId`, and `rspackVersion`.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        importMeta: {
          url: false,
          webpack: true,
          webpackContext: true,
          rspackHash: false,
        },
      },
    },
  },
};
```

`resolve` only controls whether an already enabled [`import.meta.resolve()`](#javascriptimportmetaresolve) expression is handled at compile time. To use `import.meta.resolve()`, you still need to enable `javascript.importMetaResolve`.

### javascript.exportsPresence


- Type: `'error' | 'warn' | 'auto' | false`
- Default:`'error'`


Warn or error for using non-existent exports and conflicting re-exports.

- `"error"`: Report errors.
- `"warn"`: Report warnings.
- `"auto"`: Depending on whether the module is a strict ESM, give an error if it is, otherwise give a warning.
- `false`: Disable this feature.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        exportsPresence: 'auto',
      },
    },
  },
};
```

### javascript.importExportsPresence


- Type: `'error' | 'warn' | 'auto' | false`


Warn or error for using non-existent exports, defaulting to the configuration of [module.parser.javascript.exportsPresence](#javascriptexportspresence).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        importExportsPresence: 'error',
      },
    },
  },
};
```

### javascript.reexportExportsPresence


- Type: `'error' | 'warn' | 'auto' | false`


Warn or error for conflicting re-exports, defaulting to the configuration of [module.parser.javascript.exportsPresence](#javascriptexportspresence).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        reexportExportsPresence: 'error',
      },
    },
  },
};
```

### javascript.typeReexportsPresence


[Added in v1.4.1](https://github.com/web-infra-dev/rspack/releases/tag/v1.4.1)

- **Type:** `'no-tolerant' | 'tolerant' | 'tolerant-no-check'`
- **Default:** `'no-tolerant'`

Controls error tolerance for type re-exports, commonly seen in these two scenarios:

```ts
// case 1:
export { TypeA } from './types';
// case 2:
import { TypeB } from './types';
export { TypeB };
```

When re-exporting types, since `TypeA` and `TypeB` are types but used in value namespace (`export {}`), Rspack will report warnings:

```txt
WARNING in ./re-exports.ts
  ⚠ ESModulesLinkingWarning: export 'TypeA' (reexported as 'TypeA') was not found in './types' (module has no exports)
   ╭─[2:0]
 1 │ // case 1:
 2 │ export { TypeA } from "./types";
   · ────────────────────────────────

WARNING in ./re-exports.ts
  ⚠ ESModulesLinkingWarning: export 'TypeB' (reexported as 'TypeB') was not found in './types' (module has no exports)
   ╭─[5:0]
 3 │ // case 2:
 4 │ import { TypeB } from "./types";
 5 │ export { TypeB };
   · ─────────────────
```

:::info Recommended with isolatedModules
When using Rspack to bundle TypeScript, we strongly recommend enabling [isolatedModules](https://www.typescriptlang.org/tsconfig/#isolatedModules) in tsconfig.json (also recommended with other bundlers as it matches how bundlers compile TypeScript: [.ts files are independent and compiled separately](/guide/languages/typescript.md#enable-isolatedmodules)). This will give TypeScript's own warning for type re-exports: `Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'.`
:::

- `'no-tolerant'`: Default behavior, shows errors for type re-exports.
- `'tolerant'`: Tolerates type re-exports while verifying the existence of corresponding type exports in child modules. Requires coordination with [`collectTypeScriptInfo.typeExports`](/guide/features/builtin-swc-loader.md#collecttypescriptinfotypeexports) from builtin:swc-loader to collect type export information.
- `'tolerant-no-check'`: Tolerates type re-exports without checking child modules (may incorrectly tolerate some invalid cases, though IDEs usually provide warnings). Better performance as it skeps child module checks.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        typeReexportsPresence: 'tolerant',
      },
    },
    rules: [
      {
        test: /\.(?:js|mjs|ts)$/,
        use: [
          {
            loader: 'builtin:swc-loader',
            options: {
              detectSyntax: 'auto',
              collectTypeScriptInfo: {
                typeExports: true, // Must be enabled in "tolerant" mode
              },
            },
          },
        ],
      },
    ],
  },
};
```

Please refer to [type reexports presence example](https://github.com/rstackjs/rstack-examples/tree/main/rspack/type-reexports-presence) for more details.

### javascript.worker


- Type: `string[] | boolean | { alias?: string[], url?: 'new-url-relative' }`


Provide custom syntax for Worker parsing, commonly used to support Worklet:

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        worker: [
          // Supports CSS paintWorklet
          'CSS.paintWorklet.addModule()',
          // Supports AudioWorklet, with the leading '*' indicating the recognition of a variable named 'context', for example:
          // let context = new AudioContext();
          // await context.audioWorklet.addModule(new URL("noise-processor.js", import.meta.url));
          '*context.audioWorklet.addModule()',
          // Extends default syntax: ["Worker", "SharedWorker", "navigator.serviceWorker.register()", "Worker from worker_threads"]
          '...',
        ],
      },
    },
  },
};
```

The `string[]` form is equivalent to setting the same values on `worker.alias`.
When `worker.url` is unset, Rspack keeps the existing Worker URL output. When
`worker.url` is set to `'new-url-relative'` and `output.module` is enabled,
Rspack emits a static `new URL()` expression for
`new Worker(new URL(..., import.meta.url))`. For non-ESM output, Rspack keeps
the existing runtime Worker URL output:

```js title="rspack.config.mjs"
export default {
  output: {
    module: true,
    chunkFilename: '[name].bundle.js',
  },
  module: {
    parser: {
      javascript: {
        worker: {
          url: 'new-url-relative',
        },
      },
    },
  },
};
```

```js
new Worker(new URL('./worker.js', import.meta.url));

// would become 👇
new Worker(new URL('./worker.bundle.js', import.meta.url));
```

> See [Web Workers](/guide/features/web-workers.md) for more details.

### javascript.overrideStrict


- Type: `'strict' | 'non-strict'`


Override the module to strict or non-strict.

This may affect the behavior of the module (some behaviors differ between strict and non-strict), so please configure this option carefully.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        overrideStrict: 'strict',
      },
    },
  },
};
```

### javascript.commonjs


- Type: `boolean | { exports?: boolean | 'skipInEsm' }`
- Default:`true`


Controls CommonJS-specific parser behaviour. The default `true` keeps Rspack's standard handling for CommonJS export mutations. Set `{ exports: 'skipInEsm' }` to skip rewriting CommonJS export assignments when the module is evaluated as ESM, preserving the original runtime side effects. Provide `false` to disable CommonJS export handling entirely.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        commonjs: {
          exports: 'skipInEsm',
        },
      },
    },
  },
};
```

### javascript.createRequire


- Type: `boolean | string`
- Default:`false`


Control whether Rspack parses `createRequire()` from Node.js `module` and turns the created `require` function into a statically analyzable dependency context.

When set to `true`, it is equivalent to `"createRequire from module"`. Rspack recognizes imports from both `module` and `node:module` for this default form.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        createRequire: true,
      },
    },
  },
};
```

```js title="index.js"
import { createRequire as r } from 'module';

const require = r(import.meta.url);
const value = require('./value.cjs');
```

Rspack also supports namespace and default imports:

```js title="index.js"
import moduleDefault from 'module';
import * as moduleNs from 'node:module';

moduleDefault.createRequire(import.meta.url)('./value.cjs');
moduleNs.createRequire(import.meta.url)('./value.cjs');
```

The `createRequire()` argument must be statically analyzable as a file URL or an absolute path, such as `import.meta.url`, `new URL('./dir/file.js', import.meta.url)`, or an absolute `file:` URL. When `import.meta.url` is used as the argument, Rspack treats it as the current module URL for the `createRequire` context.

You can use a string value in the form `"<specifier> from <module>"` to customize the imported specifier and module source:

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        createRequire: 'createRequire from module',
      },
    },
  },
};
```

### javascript.requireAlias


- Type: `boolean`
- Default:`false`


Control whether renaming of the CommonJS `require` function will be parsed and transformed.

When set to `true`, Rspack will parse and transform cases where `require` is assigned to a variable or passed as a parameter (e.g., `const req = require; req('./module')`).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        requireAlias: true,
      },
    },
  },
};
```

### javascript.requireAsExpression


- Type: `boolean`
- Default:`true`


Control whether `require` used as an expression will be parsed.

When set to `true`, Rspack will parse `require` when it's used as an expression (e.g., `const req = require; req('./module')`) and emit a warning. When set to `false`, this pattern will be ignored.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        requireAsExpression: false,
      },
    },
  },
};
```

### javascript.requireDynamic


- Type: `boolean`
- Default:`true`


Control whether dynamic `require` calls will be parsed.

When set to `false`, Rspack will not parse dynamic `require` calls where the module path is not a static string (e.g., `require(variable)`). This can improve build performance if your code doesn't use dynamic requires.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        requireDynamic: false,
      },
    },
  },
};
```

### javascript.requireResolve


- Type: `boolean`
- Default:`true`


Control whether `require.resolve()` calls will be parsed.

When set to `false`, Rspack will not parse `require.resolve()` calls. This can improve build performance if your code doesn't use `require.resolve()`.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        requireResolve: false,
      },
    },
  },
};
```

### javascript.importDynamic


- Type: `boolean`
- Default:`true`


Control whether dynamic `import()` calls will be parsed.

When set to `false`, Rspack will not parse dynamic `import()` calls where the module path is not a static string (e.g., `import(variable)`). This can improve build performance if your code doesn't use dynamic imports.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        importDynamic: false,
      },
    },
  },
};
```

### javascript.strictThisContextOnImports


- Type: `boolean`
- Default:`false`


Controls whether Rspack preserves the `this` binding strictly when calling exported functions as object members from imported modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        strictThisContextOnImports: false,
      },
    },
  },
};
```

This mainly affects cases where an exported function uses `this` to refer to the current module object, for example:

```js title="index.js"
import * as mod from './mod';

console.log(mod.fn());
```

```js title="mod.js"
export function fn() {
  return this.value;
}

export const value = 42;
```

In the example above, enabling this option prints `42`. When it is disabled, `value` is considered unused and removed for better tree shaking, so the result becomes `undefined`.

- When set to `true`, Rspack follows the spec more strictly and prioritizes correct runtime `this` semantics, but tree shaking can become less effective.
- When set to `false`, Rspack can generate more optimized output, but runtime `this` semantics may no longer be preserved in these patterns.

This pattern is uncommon in real-world ESM code, and enabling the option can reduce tree shaking effectiveness, so the default is `false`.

:::tip
If you run into this pattern in practice, it is usually better to avoid relying on it. If that is not possible, prefer enabling it only for specific modules with [module rule condition](/config/module-rules.md#condition).

```js title="rspack.config.mjs"
export default {
  module: {
    rules: [
      {
        test: /index\.js$/, // Only enable strictThisContextOnImports for import statements in the index.js module
        parser: {
          strictThisContextOnImports: true,
        },
      },
    ],
  },
};
```

:::

### javascript.jsx


[Added in v1.5.7](https://github.com/web-infra-dev/rspack/releases/tag/v1.5.7)

Stability: Experimental


- Type: `boolean`
- Default:`false`


Allow the JavaScript parser to understand JSX syntax so that parsing and minimization can operate on files that keep JSX in the final bundle.

Enable this option when you set the loader's JSX mode to "preserve" and want to defer the actual JSX transform to a later tool (for example, libraries that ship JSX output or rely on a custom JSX runtime).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        jsx: true,
      },
    },
  },
};
```

:::warning
This option is experimental in Rspack and may change or be removed.
:::

### javascript.importMetaResolve


[Added in v2.0.0](https://github.com/web-infra-dev/rspack/releases/tag/v2.0.0)

Stability: Experimental


- Type: `boolean`
- Default:`false`


Allow the JavaScript parser to understand `import.meta.resolve()` syntax.

Currently, `import.meta.resolve("./module")` behaves similarly to [`require.resolve("./module")`](/api/runtime-api/module-methods.md#requireresolve): it includes the module in the final bundle and returns the module ID.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      javascript: {
        importMetaResolve: true,
      },
    },
  },
};
```

:::warning
This option is experimental in Rspack and may change or be removed.
:::

### javascript.pureFunctions


Stability: Experimental


- Type: `string[]`


Manually mark top-level identifiers in matched modules as side-effect-free for pure-function-based tree shaking. Each name must resolve to a supported top-level name in the module — a function/class/variable declaration, an `import` specifier, an exported alias such as `export { foo as bar }`, or `default` for a default-exported function or arrow.

This option is mainly intended for third-party libraries whose source cannot be annotated directly. You can either configure it on the library file itself, or on a consumer file to assert that calls to a particular import are pure.

Although the option lives under `module.parser.javascript`, in practice it is usually better to apply it through `module.rules[i].parser` so you can configure `pureFunctions` more precisely for specific modules.

```js title="rspack.config.mjs"
export default {
  experiments: {
    pureFunctions: true,
  },
  module: {
    rules: [
      // Mark exports of a third-party library as pure.
      {
        test: /node_modules\/some-library\/index\.js$/,
        parser: {
          pureFunctions: ['isString'],
        },
      },
      // Or mark imports on the consumer side: calls to `cva` in this file
      // are treated as pure regardless of how the library declares itself.
      {
        test: /src\/styles\.js$/,
        parser: {
          pureFunctions: ['cva'],
        },
      },
    ],
  },
};
```

:::warning
This option only takes effect when `experiments.pureFunctions` is enabled, which is the default in production mode. Rspack emits a warning if a configured name does not appear as a top-level binding in the matched module.
:::

### \["javascript/auto"]

Parser options for `javascript/auto` modules, same as the [`javascript` parser options](#javascript).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'javascript/auto': {
        // options
      },
    },
  },
};
```

### \["javascript/dynamic"]

Parser options for `javascript/dynamic` modules, same as the [`javascript` parser options](#javascript).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'javascript/dynamic': {
        // options
      },
    },
  },
};
```

### \["javascript/esm"]

Parser options for `javascript/esm` modules, same as the [`javascript` parser options](#javascript).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'javascript/esm': {
        // options
      },
    },
  },
};
```

### json

Parser options for `json` modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      json: {
        // options
      },
    },
  },
};
```

### json.exportsDepth

- **Type:** `number`
- **Default:** production mode is `Number.MAX_SAFE_INTEGER`, development mode is `1`

The depth of json dependency flagged as `exportInfo`.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      json: {
        // For example, for the following json
        // {
        //   "depth_1": {
        //     "depth_2": {
        //       "depth_3": "foo"
        //     }
        //   },
        //   "_depth_1": "bar"
        // }
        // when `exportsDepth: 1`, `depth_2` and `depth_3` will not be flagged as `exportInfo`.
        exportsDepth: 1,
      },
    },
  },
};
```

### json.parse

- **Type:** `(source: string) => any`
- **Default:** `undefined`

Customize how Rspack parses the source of `json` modules. The function receives the module source as a string. It is called synchronously and must return JSON-serializable data, such as an object, array, string, number, boolean, or `null`.

Rspack serializes the returned value with `JSON.stringify` and then parses that serialized JSON as the module data, so values that cannot be represented as valid JSON should not be returned. For normal JSON files you do not need to configure this option; it is mainly useful when modules are treated as `type: 'json'` but need custom source-to-data conversion.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      json: {
        parse: (source) => {
          return JSON.parse(source);
        },
      },
    },
  },
};
```

You can also use this option through `module.rules[].parser` when the matched rule sets `type: 'json'`. For example, parse `.json5` files as JSON modules:

```js title="rspack.config.mjs"
import JSON5 from 'json5';

export default {
  module: {
    rules: [
      {
        test: /\.json5$/,
        type: 'json',
        parser: {
          parse: JSON5.parse,
        },
      },
    ],
  },
};
```

### \["css/auto"]

Parser options for `css/auto` modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        // options
      },
    },
  },
};
```

### \["css/auto"].exportType

- **Type:** `'link' | 'text' | 'css-style-sheet' | 'style'`
- **Default:** `'link'`

Configure how CSS content is exported to JavaScript.

By default, `exportType` is `'link'`, which emits CSS as stylesheet output and loads it with the built-in CSS loading runtime.

- `'link'`: emit the CSS as stylesheet output and keep CSS module exports available.
- `'text'`: export the generated CSS text as the default export.
- `'css-style-sheet'`: export a `CSSStyleSheet` instance as the default export.
- `'style'`: inject the generated CSS into the document through `<style>` tags at runtime.

When using `exportType: 'text'` or `exportType: 'css-style-sheet'`, the generated CSS becomes part of the JavaScript module and no separate CSS asset is emitted for that module.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        exportType: 'text',
      },
    },
  },
};
```

### \["css/auto"].namedExports

- **Type:** `boolean`
- **Default:** `true`

Use ES modules named export for CSS exports.

When using `namedExports: true`, you can use namespace export or named export:

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        namedExports: true,
      },
    },
  },
};
```

```js
// namespace export
import * as classes from './index.module.css';
// named export
import { class1, class2 } from './index.module.css';
```

When using `namedExports: false`, in addition to namespace export and named export, default export can also be used:

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        namedExports: false,
      },
    },
  },
};
```

```js
// namespace export
import * as classes from './index.module.css';
// named export
import { class1, class2 } from './index.module.css';
// default export
import classes from './index.module.css';
// default export and named export
import classes, { class1, class2 } from './index.module.css';
```

### \["css/auto"].url

- **Type:** `boolean`
- **Default:** `true`

Allow to enable/disables handling the CSS functions url.

When using `url: true`, Rspack will resolve the path in `url` function, the resolve file will be treated as an asset.
When using `url: false`, Rspack will ignore the path in the `url` function, keep the content unchanged.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      css: {
        url: true,
      },
    },
  },
};
```

### \["css/auto"].resolveImport


[Added in v1.7.2](https://github.com/web-infra-dev/rspack/releases/tag/v1.7.2)

- **Type:** `boolean | ((context: { url: string, media: string | undefined, resourcePath: string, supports: string | undefined, layer: string | undefined }) => boolean)`
- **Default:** `true`

Whether to resolve `@import` syntax.

- `true`: enable processing of `@import` rules (default).
- `false`: disable processing of `@import` rules.
- `function`: only process `@import` rules that satisfy the condition.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        resolveImport: ({ url }) => {
          return url.includes('style.css');
        },
      },
    },
  },
};
```

### \["css/auto"].import

- **Type:** `boolean`
- **Default:** `true`

Whether to handle CSS `@import` at-rules.

- `true`: resolve and process `@import` rules (default).
- `false`: leave `@import` rules unchanged in the generated CSS.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        import: true,
      },
    },
  },
};
```

### \["css/auto"].animation

- **Type:** `boolean`
- **Default:** `true`

Enable or disable renaming local `@keyframes` identifiers and their `animation` or `animation-name` usages.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        animation: true,
      },
    },
  },
};
```

### \["css/auto"].customIdents

- **Type:** `boolean`
- **Default:** `true`

Enable or disable renaming custom identifiers, such as local `@counter-style` and `@font-palette-values` names.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        customIdents: true,
      },
    },
  },
};
```

### \["css/auto"].container

- **Type:** `boolean`
- **Default:** `true`

Enable or disable renaming local CSS container names and their usages, such as `container-name`, `container`, and `@container`.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        container: true,
      },
    },
  },
};
```

### \["css/auto"].dashedIdents

- **Type:** `boolean`
- **Default:** `true`

Enable or disable renaming dashed identifiers, such as CSS custom properties and `@property` declarations.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        dashedIdents: true,
      },
    },
  },
};
```

### \["css/auto"].function

- **Type:** `boolean`
- **Default:** `true`

Enable or disable renaming local CSS function names and their usages, such as `@function --fn` and `--fn()`.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        function: true,
      },
    },
  },
};
```

### \["css/auto"].grid

- **Type:** `boolean`
- **Default:** `true`

Enable or disable renaming local CSS grid line and area names and their usages, such as `grid-template-areas`, `grid-area`, and `grid-row`.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        grid: true,
      },
    },
  },
};
```

### \["css/auto"].pure

- **Type:** `boolean`
- **Default:** `false`

Enable strict pure mode for CSS Modules. When enabled, every selector in a CSS Module must contain at least one local class or id selector.

For `css/auto`, this check only applies to files that are treated as CSS Modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/auto': {
        pure: true,
      },
    },
  },
};
```

### css

Parser options for `css` modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      css: {
        // options
      },
    },
  },
};
```

### css.exportType

Same as [`module.parser["css/auto"].exportType`](#cssautoexporttype).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      css: {
        exportType: 'text',
      },
    },
  },
};
```

### css.namedExports

Same as [`module.parser["css/auto"].namedExports`](#cssautonamedexports).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      css: {
        namedExports: true,
      },
    },
  },
};
```

### css.url

Same as [`module.parser["css/auto"].url`](#cssautourl).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      css: {
        url: true,
      },
    },
  },
};
```

### css.resolveImport

Same as [`module.parser["css/auto"].resolveImport`](#cssautoresolveimport).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      css: {
        resolveImport: ({ url }) => {
          return url.includes('style.css');
        },
      },
    },
  },
};
```

### css.import

Same as [`module.parser["css/auto"].import`](#cssautoimport).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      css: {
        import: true,
      },
    },
  },
};
```

### \["css/global"]

Parser options for `css/global` modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        // options
      },
    },
  },
};
```

### \["css/global"].exportType

Same as [`module.parser["css/auto"].exportType`](#cssautoexporttype).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        exportType: 'style',
      },
    },
  },
};
```

### \["css/global"].namedExports

Same as [`module.parser["css/auto"].namedExports`](#cssautonamedexports).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        namedExports: true,
      },
    },
  },
};
```

### \["css/global"].url

Same as [`module.parser["css/auto"].url`](#cssautourl).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        url: true,
      },
    },
  },
};
```

### \["css/global"].resolveImport

Same as [`module.parser["css/auto"].resolveImport`](#cssautoresolveimport).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        resolveImport: ({ url }) => {
          return url.includes('style.css');
        },
      },
    },
  },
};
```

### \["css/global"].import

Same as [`module.parser["css/auto"].import`](#cssautoimport).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        import: true,
      },
    },
  },
};
```

### \["css/global"].animation

Same as [`module.parser["css/auto"].animation`](#cssautoanimation).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        animation: true,
      },
    },
  },
};
```

### \["css/global"].container

Same as [`module.parser["css/auto"].container`](#cssautocontainer).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        container: true,
      },
    },
  },
};
```

### \["css/global"].customIdents

Same as [`module.parser["css/auto"].customIdents`](#cssautocustomidents).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        customIdents: true,
      },
    },
  },
};
```

### \["css/global"].dashedIdents

Same as [`module.parser["css/auto"].dashedIdents`](#cssautodashedidents).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        dashedIdents: true,
      },
    },
  },
};
```

### \["css/global"].function

Same as [`module.parser["css/auto"].function`](#cssautofunction).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        function: true,
      },
    },
  },
};
```

### \["css/global"].grid

Same as [`module.parser["css/auto"].grid`](#cssautogrid).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/global': {
        grid: true,
      },
    },
  },
};
```

### \["css/module"]

Parser options for `css/module` modules.

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        // options
      },
    },
  },
};
```

### \["css/module"].exportType

Same as [`module.parser["css/auto"].exportType`](#cssautoexporttype).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        exportType: 'css-style-sheet',
      },
    },
  },
};
```

### \["css/module"].namedExports

Same as [`module.parser["css/auto"].namedExports`](#cssautonamedexports).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        namedExports: true,
      },
    },
  },
};
```

### \["css/module"].url

Same as [`module.parser["css/auto"].url`](#cssautourl).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        url: true,
      },
    },
  },
};
```

### \["css/module"].resolveImport

Same as [`module.parser["css/auto"].resolveImport`](#cssautoresolveimport).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        resolveImport: ({ url }) => {
          return url.includes('style.css');
        },
      },
    },
  },
};
```

### \["css/module"].import

Same as [`module.parser["css/auto"].import`](#cssautoimport).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        import: true,
      },
    },
  },
};
```

### \["css/module"].animation

Same as [`module.parser["css/auto"].animation`](#cssautoanimation).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        animation: true,
      },
    },
  },
};
```

### \["css/module"].container

Same as [`module.parser["css/auto"].container`](#cssautocontainer).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        container: true,
      },
    },
  },
};
```

### \["css/module"].customIdents

Same as [`module.parser["css/auto"].customIdents`](#cssautocustomidents).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        customIdents: true,
      },
    },
  },
};
```

### \["css/module"].dashedIdents

Same as [`module.parser["css/auto"].dashedIdents`](#cssautodashedidents).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        dashedIdents: true,
      },
    },
  },
};
```

### \["css/module"].function

Same as [`module.parser["css/auto"].function`](#cssautofunction).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        function: true,
      },
    },
  },
};
```

### \["css/module"].grid

Same as [`module.parser["css/auto"].grid`](#cssautogrid).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        grid: true,
      },
    },
  },
};
```

### \["css/module"].pure

Same as [`module.parser["css/auto"].pure`](#cssautopure).

```js title="rspack.config.mjs"
export default {
  module: {
    parser: {
      'css/module': {
        pure: true,
      },
    },
  },
};
```


This page is adapted from [webpack documentation](https://webpack.js.org/configuration/module/) under the [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), with modifications.

