Skip to content

Commit 6aef338

Browse files
committed
chore: update
1 parent 89012a8 commit 6aef338

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

packages/plugin-dts/src/utils.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ export async function redirectDtsImports(
180180
return;
181181
}
182182

183-
const extensions = dtsExtension
184-
.replace(/\.d\.ts$/, '.js')
185-
.replace(/\.d\.cts$/, '.cjs')
186-
.replace(/\.d\.mts$/, '.mjs');
187183
const content = await fsP.readFile(dtsFile, 'utf-8');
188184
const code = new MagicString(content);
189185
const sgNode = (await parseAsync('typescript', content)).root();
@@ -231,26 +227,32 @@ export async function redirectDtsImports(
231227
};
232228
});
233229

230+
const result = loadConfig(tsconfigPath);
231+
232+
if (result.resultType === 'failed') {
233+
logger.error(result.message);
234+
return;
235+
}
236+
237+
const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result;
238+
const matchPath = createMatchPath(
239+
absoluteBaseUrl,
240+
paths,
241+
mainFields,
242+
addMatchAll,
243+
);
244+
245+
const extensions = dtsExtension
246+
.replace(/\.d\.ts$/, '.js')
247+
.replace(/\.d\.cts$/, '.cjs')
248+
.replace(/\.d\.mts$/, '.mjs');
249+
234250
for (const imp of matchModule) {
235251
const { n: importPath, s: start, e: end } = imp;
236252

237253
if (!importPath) continue;
238254

239255
try {
240-
const result = loadConfig(tsconfigPath);
241-
242-
if (result.resultType === 'failed') {
243-
logger.error(result.message);
244-
return;
245-
}
246-
247-
const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result;
248-
const matchPath = createMatchPath(
249-
absoluteBaseUrl,
250-
paths,
251-
mainFields,
252-
addMatchAll,
253-
);
254256
const absoluteImportPath = matchPath(importPath, undefined, undefined, [
255257
'.jsx',
256258
'.tsx',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ overviewHeaders: [2, 3]
66

77
:::info
88

9-
`redirect`[bundleless 模式](/guide/basic/output-structure#bundle--bundleless) 的特定配置。该配置在 bundle 模式下不会生效,因为所有产物文件都被打包成一个文件,不需要进行路径的重定向
9+
`redirect`[bundleless 模式](/guide/basic/output-structure#bundle--bundleless) 的特定配置。该配置在 bundle 模式下不会生效,因为所有产物文件都被打包成一个文件,不需要进行文件导入路径的重定向
1010

1111
:::
1212

0 commit comments

Comments
 (0)