|
| 1 | +import { getRspackMajorVersion } from '../../../helpers/index.js'; |
1 | 2 | import { getMinimizerConfig } from './getMinimizerConfig.js'; |
2 | 3 |
|
3 | | -function getExperimentsConfig(bundler: 'rspack' | 'webpack') { |
| 4 | +function getExperimentsConfig(bundler: 'rspack' | 'webpack', rootDir: string) { |
4 | 5 | if (bundler === 'rspack') { |
5 | | - return { parallelLoader: true }; |
| 6 | + const rspackMajor = getRspackMajorVersion(rootDir) ?? 1; |
| 7 | + if (rspackMajor < 2) { |
| 8 | + return { parallelLoader: true }; |
| 9 | + } |
| 10 | + // Rspack 2 removed `experiments.parallelLoader` (parallel loading is |
| 11 | + // stable and opt-in per rule via `use[].parallel`) - nothing to set. |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +function getModuleConfig(bundler: 'rspack' | 'webpack', rootDir: string) { |
| 16 | + if (bundler === 'rspack') { |
| 17 | + const rspackMajor = getRspackMajorVersion(rootDir) ?? 1; |
| 18 | + if (rspackMajor >= 2) { |
| 19 | + // Rspack 2 changed the `exportsPresence` default from 'warn' to 'error', |
| 20 | + // which breaks builds on invalid imports inside node_modules - a common |
| 21 | + // occurrence in the React Native ecosystem that Metro tolerates. |
| 22 | + // Restore Metro-like leniency by default; users can override this |
| 23 | + // in their project config. |
| 24 | + return { |
| 25 | + parser: { javascript: { exportsPresence: 'auto' as const } }, |
| 26 | + }; |
| 27 | + } |
6 | 28 | } |
7 | 29 | } |
8 | 30 |
|
9 | 31 | export async function getRepackConfig( |
10 | 32 | bundler: 'rspack' | 'webpack', |
11 | 33 | rootDir: string |
12 | 34 | ) { |
13 | | - const experiments = getExperimentsConfig(bundler); |
| 35 | + const experiments = getExperimentsConfig(bundler, rootDir); |
| 36 | + const moduleConfiguration = getModuleConfig(bundler, rootDir); |
14 | 37 | const minimizerConfiguration = await getMinimizerConfig(bundler, rootDir); |
15 | 38 |
|
16 | 39 | return { |
17 | 40 | devtool: 'source-map', |
18 | 41 | experiments, |
| 42 | + module: moduleConfiguration, |
19 | 43 | output: { |
20 | 44 | clean: true, |
21 | 45 | hashFunction: 'xxhash64', |
|
0 commit comments