|
1 | 1 | import fs from 'node:fs'; |
2 | | -import path, { dirname, isAbsolute, join } from 'node:path'; |
| 2 | +import path, { dirname, extname, isAbsolute, join } from 'node:path'; |
3 | 3 | import { |
4 | 4 | type RsbuildConfig, |
5 | 5 | type RsbuildInstance, |
@@ -475,13 +475,18 @@ const composeBundleConfig = ( |
475 | 475 | // Prevent from externalizing entry modules here. |
476 | 476 | if (data.contextInfo.issuer) { |
477 | 477 | // Node.js ECMAScript module loader does no extension searching. |
478 | | - // So we add a file extension here when data.request is a relative path |
479 | | - return callback( |
480 | | - null, |
481 | | - data.request[0] === '.' |
482 | | - ? `${data.request}${jsExtension}` |
483 | | - : data.request, |
484 | | - ); |
| 478 | + // Add a file extension according to autoExtension config |
| 479 | + // when data.request is a relative path and do not have an extension. |
| 480 | + // If data.request already have an extension, we replace it with new extension |
| 481 | + // This may result in a change in semantics, |
| 482 | + // user should use copy to keep origin file or use another separate entry to deal this |
| 483 | + let request = data.request; |
| 484 | + if (data.request[0] === '.') { |
| 485 | + request = extname(data.request) |
| 486 | + ? request.replace(/\.[^.]+$/, jsExtension) |
| 487 | + : `${request}${jsExtension}`; |
| 488 | + } |
| 489 | + return callback(null, request); |
485 | 490 | } |
486 | 491 | callback(); |
487 | 492 | }, |
|
0 commit comments