Skip to content

Commit c9bd56f

Browse files
authored
Merge pull request #173 from rollup/sync-ab7bfa8f
docs(en): merge rollup/master into rollup-docs-cn/master @ ab7bfa8
2 parents e298f24 + 3166f52 commit c9bd56f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+807
-141
lines changed

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# rollup changelog
22

3+
## 4.36.0
4+
5+
_2025-03-17_
6+
7+
### Features
8+
9+
- Extend `renderDynamicImport` hook to provide information about static dependencies of the imported module (#5870)
10+
- Export several additional types used by Vite (#5879)
11+
12+
### Bug Fixes
13+
14+
- Do not merge chunks if that would create a top-level await cycle between chunks (#5843)
15+
16+
### Pull Requests
17+
18+
- [#5843](https://github.com/rollup/rollup/pull/5843): avoiding top level await circular (@TrickyPi, @lukastaegert)
19+
- [#5870](https://github.com/rollup/rollup/pull/5870): draft for extended renderDynamicImport hook (@iczero, @lukastaegert)
20+
- [#5876](https://github.com/rollup/rollup/pull/5876): Update axios overrides to 1.8.2 (@vadym-khodak)
21+
- [#5877](https://github.com/rollup/rollup/pull/5877): chore(deps): update dependency eslint-plugin-vue to v10 (@renovate[bot])
22+
- [#5878](https://github.com/rollup/rollup/pull/5878): fix(deps): lock file maintenance minor/patch updates (@renovate[bot])
23+
- [#5879](https://github.com/rollup/rollup/pull/5879): fix: export types (@sxzz)
24+
325
## 4.35.0
426

527
_2025-03-08_

browser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rollup/browser",
3-
"version": "4.35.0",
3+
"version": "4.36.0",
44
"description": "Next-generation ES module bundler browser build",
55
"main": "dist/rollup.browser.js",
66
"module": "dist/es/rollup.browser.js",

docs/plugin-development/index.md

+74-3
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,38 @@ type renderDynamicImportHook = (options: {
10591059
format: string;
10601060
moduleId: string;
10611061
targetModuleId: string | null;
1062+
chunk: PreRenderedChunkWithFileName;
1063+
targetChunk: PreRenderedChunkWithFileName;
1064+
getTargetChunkImports: () => DynamicImportTargetChunk[] | null;
10621065
}) => { left: string; right: string } | null;
1066+
1067+
type PreRenderedChunkWithFileName = PreRenderedChunk & { fileName: string };
1068+
1069+
type DynamicImportTargetChunk =
1070+
| ImportedInternalChunk
1071+
| ImportedExternalChunk;
1072+
1073+
interface ImportedInternalChunk {
1074+
type: 'internal';
1075+
fileName: string;
1076+
resolvedImportPath: string;
1077+
chunk: PreRenderedChunk;
1078+
}
1079+
1080+
interface ImportedExternalChunk {
1081+
type: 'external';
1082+
fileName: string;
1083+
resolvedImportPath: string;
1084+
}
10631085
```
10641086

1065-
此钩子通过提供导入表达式参数左侧(`import(`)和右侧(`)`)的代码替换,提供了对动态导入如何呈现的细粒度控制。返回`null`将推迟到此类型的其他钩子,最终呈现特定于格式的默认值。
1087+
请参阅 [`chunkFileNames`](../configuration-options/index.md#output-chunkfilenames) 选项,以了解 `PreRenderedChunk` 类型的相关信息。
1088+
1089+
这个钩子函数提供了对动态导入渲染的精细控制,它通过替换导入表达式参数左侧(`import(`)和右(`)`)侧的代码实现这一功能。如果返回 `null`,则会降级到其他同类型的钩子函数,最终渲染出特定格式的默认值。
10661090

1067-
`format` 是呈现的输出格式, `moduleId` 是执行动态导入的模块的 ID。如果导入可以解析为内部或外部 ID,则 `targetModuleId` 将设置为此 ID,否则将为 `null`。如果动态导入包含由 [`resolveDynamicImport`](#resolvedynamicimport) 钩子解析为替换字符串的非字符串表达式,则 `customResolution` 将包含该字符串。
1091+
`format` 是渲染的输出格式,`moduleId` 是进行动态导入的模块的 id。如果导入可以被解析为内部或外部 id,那么 `targetModuleId` 将被设置为这个 id,否则它将是 `null`。如果动态导入包含了一个非字符串表达式,这个表达式被 [`resolveDynamicImport`](#resolvedynamicimport) 钩子函数解析为一个替换字符串,那么 `customResolution` 将包含那个字符串。`chunk``targetChunk` 分别提供了执行导入的块和被导入的块(目标块)的额外信息。`getTargetChunkImports` 返回一个数组,包含了被目标块导入的块。如果目标块未解析或是外部的,`targetChunk` 将为 null,`getTargetChunkImports` 也将返回 null。
1092+
1093+
`PreRenderedChunkWithFileName` 类型与 `PreRenderedChunk` 类型相同,只是多了一个 `fileName` 字段,这个字段包含了块的路径和文件名。如果块文件名格式包含了哈希,`fileName` 可能会包含一个占位符。
10681094

10691095
以下代码将使用自定义处理程序替换所有动态导入,添加 `import.meta.url` 作为第二个参数,以允许处理程序正确解析相对导入:
10701096

@@ -1116,7 +1142,52 @@ function retainImportExpressionPlugin() {
11161142
}
11171143
```
11181144
1119-
请注意,当此钩子在非 ES 格式中重写动态导入时,不会生成任何交互代码以确保例如默认导出可用作`.default`。插件有责任确保重写的动态导入返回一个 Promise,该 Promise 解析为适当的命名空间对象。
1145+
当进行动态导入时,浏览器会获取并解析请求的模块。如果目标模块被发现有导入,并且这些导入还未被获取,浏览器需要进行更多的网络请求才能执行该模块。这将导致额外一轮网络往返的延迟。对于静态模块,Rollup 会提升转移依赖([`hoistTransitiveDependencies`](../configuration-options/index.md#output-hoisttransitiveimports)),以防止这种情况发生。然而,目前还没有自动为动态导入执行依赖提升的操作。
1146+
1147+
以下的插件可以实现类似于动态导入预加载的功能:
1148+
1149+
```js twoslash
1150+
// ---cut-start---
1151+
/** @returns {import('rollup').Plugin} */
1152+
// ---cut-end---
1153+
function dynamicImportDependencyPreloader() {
1154+
return {
1155+
name: 'dynamic-import-dependency-preloader',
1156+
renderDynamicImport({ getTargetChunkImports }) {
1157+
const transitiveImports = getTargetChunkImports();
1158+
if (transitiveImports && transitiveImports.length > 0) {
1159+
const preload = getTargetChunkImports()
1160+
.map(
1161+
chunk => `\t/* preload */ import(${chunk.resolvedImportPath})`
1162+
)
1163+
.join(',\n');
1164+
return {
1165+
left: `(\n${preload},\n\timport(`,
1166+
right: `)\n)`
1167+
};
1168+
} else {
1169+
return null;
1170+
}
1171+
}
1172+
};
1173+
}
1174+
```
1175+
1176+
<!-- prettier-ignore-start -->
1177+
```js
1178+
// input
1179+
import('./lib.js');
1180+
1181+
// output
1182+
(
1183+
/* preload */ import('./dependency-1.js'),
1184+
/* preload */ import('./dependency-2.js'),
1185+
import('./lib.js');
1186+
);
1187+
```
1188+
<!-- prettier-ignore-end -->
1189+
1190+
请注意,当此钩子在非 ES 格式中重写动态导入时,不会生成任何交互代码以确保例如默认导出可用作 `.default`。插件有责任确保重写的动态导入返回一个 Promise,该 Promise 解析为适当的命名空间对象。
11201191
11211192
### renderError
11221193

package-lock.json

+21-98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup",
3-
"version": "4.35.0",
3+
"version": "4.36.0",
44
"description": "Next-generation ES module bundler",
55
"main": "dist/rollup.js",
66
"module": "dist/es/rollup.js",
@@ -160,7 +160,7 @@
160160
"eslint-config-prettier": "^10.1.1",
161161
"eslint-plugin-prettier": "^5.2.3",
162162
"eslint-plugin-unicorn": "^57.0.0",
163-
"eslint-plugin-vue": "^9.33.0",
163+
"eslint-plugin-vue": "^10.0.0",
164164
"fixturify": "^3.0.0",
165165
"flru": "^1.0.2",
166166
"fs-extra": "^11.3.0",
@@ -203,7 +203,7 @@
203203
"yargs-parser": "^21.1.1"
204204
},
205205
"overrides": {
206-
"axios": "^1.8.1",
206+
"axios": "^1.8.3",
207207
"semver": "^7.7.1",
208208
"readable-stream": "npm:@built-in/readable-stream@1",
209209
"esbuild": ">0.24.2"

src/Bundle.ts

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default class Bundle {
7171
this.pluginDriver.setChunkInformation(this.facadeChunkByModule);
7272
for (const chunk of chunks) {
7373
chunk.generateExports();
74+
chunk.inlineTransitiveImports();
7475
}
7576

7677
timeEnd('generate chunks', 2);

0 commit comments

Comments
 (0)