Skip to content

Commit cf6dd24

Browse files
committed
chore: update
1 parent a48fa54 commit cf6dd24

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

packages/core/src/config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
RSLIB_CSS_ENTRY_FLAG,
2727
composeCssConfig,
2828
cssExternalHandler,
29+
isCssFile,
2930
isCssGlobalFile,
3031
} from './css/cssConfig';
3132
import { composeEntryChunkConfig } from './plugins/EntryChunkPlugin';
@@ -1025,17 +1026,18 @@ const composeBundlelessExternalConfig = (
10251026
} catch (e) {
10261027
// e.g. A react component library importing and using 'react' but while not defining
10271028
// it in devDependencies and peerDependencies. Preserve 'react' as-is if so.
1028-
logger.warn(
1029-
`Failed to resolve module ${color.green(`"${resolvedRequest}"`)} from ${color.green(contextInfo.issuer)}. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.`,
1030-
);
1029+
if(!isCssFile(contextInfo.issuer)) {
1030+
logger.warn(
1031+
`Failed to resolve module ${color.green(`"${resolvedRequest}"`)} from ${color.green(contextInfo.issuer)}. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.`,
1032+
);
1033+
}
10311034
}
10321035
}
10331036

10341037
const cssExternal = cssExternalHandler(
10351038
resolvedRequest,
10361039
callback,
10371040
jsExtension,
1038-
jsRedirectExtension,
10391041
cssModulesAuto,
10401042
isStyleRedirected,
10411043
);

packages/core/src/css/cssConfig.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export function cssExternalHandler(
8383
request: string,
8484
callback: ExternalCallback,
8585
jsExtension: string,
86-
jsRedirectExtension: boolean,
8786
auto: CssLoaderOptionsAuto,
8887
isStyleRedirect: boolean,
8988
): void | false {
@@ -104,9 +103,7 @@ export function cssExternalHandler(
104103
if (isCssModulesRequest) {
105104
return callback(
106105
undefined,
107-
jsRedirectExtension
108-
? request.replace(/\.[^.]+$/, jsExtension)
109-
: request,
106+
request.replace(/\.[^.]+$/, jsExtension)
110107
);
111108
}
112109
return callback(undefined, request.replace(/\.[^.]+$/, '.css'));

tests/integration/redirect/js-import-css/rslib.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@ export default defineConfig({
55
lib: [
66
generateBundleEsmConfig({
77
bundle: false,
8+
autoExtension: false,
9+
redirect: {
10+
js: {
11+
extension: false
12+
}
13+
}
814
}),
915
generateBundleCjsConfig({
1016
bundle: false,
17+
autoExtension: false,
18+
redirect: {
19+
js: {
20+
extension: false
21+
}
22+
}
1123
}),
1224
],
1325
source: {

website/docs/zh/config/lib/auto-extension.mdx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313

1414
-`package.json` 中设置 `type: commonjs` 或没有 `type` 字段时,`cjs` 格式使用 `.js``esm` 格式使用 `.mjs`
1515

16-
:::warning
17-
18-
[bundle](/config/lib/bundle) 设置为 `false`(即 bundleless 模式)时,你需要在源代码中写完整的路径,而不是省略目录索引(例如,用 `'./foo'` 作为 `'./foo/index.js'` 的简写)。
19-
20-
举例来说,如果 `foo` 是一个文件夹,你需要将 `import * from './foo'` 改写为 `import * from './foo/index'`
21-
22-
:::
23-
2416
`autoExtension` 设置为 `false` 时,文件扩展名将默认为 `.js`
2517

2618
## 自定义扩展名

website/docs/zh/config/lib/redirect.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,19 @@ const defaultRedirect = {
103103

104104
是否重定向样式文件的导入路径。
105105

106-
例如,当导入 `.less` 文件时,它将被重写为 `.css` 文件:
106+
当设置为 `true` 时,导入样式文件时,路径将被重写为 `.css` 文件,当导入 [CSS Modules](/zh/config/rsbuild/output#outputcssmodules) 时,路径将被重写为到对应的 JavaScript 输出文件。
107+
108+
当设置为 `false` 时,文件扩展名将保持原始导入路径中的不变。
109+
110+
111+
- 示例:
112+
113+
默认情况下,当从 `.less` 文件导入时:
107114

108115
```ts
109116
import './index.less'; // source code ↓
110117
import './index.css'; // output file
118+
119+
import styles from './index.module.less'; // source code ↓
120+
import styles from './index.module.mjs'; // output file
111121
```

0 commit comments

Comments
 (0)