Skip to content

Commit e80fac7

Browse files
authored
Merge pull request #177 from rollup/sync-72858cb1
docs(en): merge rollup/master into rollup-docs-cn/master @ 72858cb
2 parents 085f418 + 103e4f8 commit e80fac7

File tree

60 files changed

+1194
-566
lines changed

Some content is hidden

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

60 files changed

+1194
-566
lines changed

.github/workflows/build-and-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: Lint
5252
run: npm run ci:lint
5353
- name: Vulnerabilities
54-
run: npm audit
54+
run: npm audit --audit-level moderate
5555
- name: Optional Dependencies
5656
run: npm run test:package
5757
- name: Generated Code

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
# rollup changelog
22

3+
## 4.43.0
4+
5+
_2025-06-11_
6+
7+
### Features
8+
9+
- Provide new `fs` option and `this.fs` API to replace file system (#5944)
10+
11+
### Pull Requests
12+
13+
- [#5944](https://github.com/rollup/rollup/pull/5944): feat(options): Add an option for overriding the file system module in the JS API (@EggDice, @lukastaegert)
14+
15+
## 4.42.0
16+
17+
_2025-06-06_
18+
19+
### Features
20+
21+
- Add option to allow the input to be located in the output in watch mode (#5966)
22+
23+
### Pull Requests
24+
25+
- [#5966](https://github.com/rollup/rollup/pull/5966): feat: watch mode add `allowInputInsideOutputPath` option (@btea, @lukastaegert)
26+
27+
## 4.41.2
28+
29+
_2025-06-06_
30+
31+
### Bug Fixes
32+
33+
- Detect named export usages in dynamic imports with `then` and non-arrow function expressions (#5977)
34+
- Do not replace usages of constant variables with their values for readability (#5968)
35+
36+
### Pull Requests
37+
38+
- [#5968](https://github.com/rollup/rollup/pull/5968): fix: preserve constant identifiers in unary expressions instead of magic numbers (@OmkarJ13, @lukastaegert)
39+
- [#5969](https://github.com/rollup/rollup/pull/5969): chore(deps): update dependency yargs-parser to v22 (@renovate[bot], @lukastaegert)
40+
- [#5970](https://github.com/rollup/rollup/pull/5970): chore(deps): lock file maintenance minor/patch updates (@renovate[bot])
41+
- [#5971](https://github.com/rollup/rollup/pull/5971): chore(deps): lock file maintenance (@renovate[bot])
42+
- [#5976](https://github.com/rollup/rollup/pull/5976): Update README.md (@ftlno, @lukastaegert)
43+
- [#5977](https://github.com/rollup/rollup/pull/5977): fix: consider function expression in thenable when tree-shaking dynamic imports (@TrickyPi)
44+
- [#5981](https://github.com/rollup/rollup/pull/5981): fix(deps): lock file maintenance minor/patch updates (@renovate[bot])
45+
- [#5982](https://github.com/rollup/rollup/pull/5982): Debug/fix watch pipeline (@lukastaegert)
46+
347
## 4.41.1
448

549
_2025-05-24_

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
6666

6767
## 特别赞助
6868

69-
<a href="https://www.tngtech.com/en/index.html" target="_blank"><img src="https://www.tngtech.com/fileadmin/Public/Images/Logos/TNG_Logo_medium_400x64.svg" alt="TNG Logo" width="280"/></a>
69+
<a href="https://www.tngtech.com/en/index.html" target="_blank"><img src="https://avatars.githubusercontent.com/u/432256?s=200&v=4" alt="TNG Logo"/></a>
7070

7171
TNG 自 2017 年以来一直在支持 [Lukas Taegert-Atkinson](https://github.com/lukastaegert) 在 Rollup 上的工作。
7272

browser/package.json

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

browser/src/fs.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
import type { RollupFsModule } from '../../src/rollup/types';
12
import { throwNoFileSystem } from './error';
3+
import type * as FsType from './fs.ts';
24

5+
// Ensure this satisfies the RollupFsModule API, will be removed by tree-shaking
6+
const _typeTest = null as unknown as typeof FsType satisfies RollupFsModule;
7+
8+
export const appendFile = throwNoFileSystem('fs.appendFile');
9+
export const copyFile = throwNoFileSystem('fs.copyFile');
310
export const mkdir = throwNoFileSystem('fs.mkdir');
11+
export const mkdtemp = throwNoFileSystem('fs.mkdtemp');
12+
export const readdir = throwNoFileSystem('fs.readdir');
413
export const readFile = throwNoFileSystem('fs.readFile');
14+
export const realpath = throwNoFileSystem('fs.realpath');
15+
export const rename = throwNoFileSystem('fs.rename');
16+
export const rmdir = throwNoFileSystem('fs.rmdir');
17+
export const stat = throwNoFileSystem('fs.stat');
18+
export const lstat = throwNoFileSystem('fs.lstat');
19+
export const unlink = throwNoFileSystem('fs.unlink');
520
export const writeFile = throwNoFileSystem('fs.writeFile');

browser/src/resolveId.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

build-plugins/replace-browser-modules.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ import type { Plugin } from 'vite';
55

66
const resolve = (path: string) => fileURLToPath(new URL(`../${path}`, import.meta.url));
77

8-
const JS_REPLACED_MODULES = [
9-
'fs',
10-
'hookActions',
11-
'path',
12-
'performance',
13-
'process',
14-
'resolveId',
15-
'initWasm'
16-
];
8+
const JS_REPLACED_MODULES = ['fs', 'hookActions', 'path', 'performance', 'process', 'initWasm'];
179

1810
type ModulesMap = [string, string][];
1911

cli/help.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ Basic options:
9090
--no-treeshake.unknownGlobalSideEffects Assume unknown globals do not throw
9191
--validate Validate output
9292
--waitForBundleInput Wait for bundle input files
93+
--watch.allowInputInsideOutputPath Whether the input path is allowed to be a
94+
subpath of the output path
9395
--watch.buildDelay <number> Throttle watch rebuilds
9496
--no-watch.clearScreen Do not clear the screen when rebuilding
9597
--watch.exclude <files> Exclude files from being watched

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export default defineConfig({
117117
link: '/es-module-syntax/',
118118
text: 'ES 模块语法'
119119
},
120+
{
121+
link: '/browser/',
122+
text: '在浏览器中运行 Rollup'
123+
},
120124
{
121125
link: '/faqs/',
122126
text: '常见问题'

docs/browser/index.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: 在浏览器中运行 Rollup
3+
---
4+
5+
# {{ $frontmatter.title }}
6+
7+
[[toc]]
8+
9+
## 浏览器构建 {#the-browser-build}
10+
11+
虽然常规的 Rollup 构建依赖于一些 NodeJS 内置库,但也有一个仅使用浏览器 API 的浏览器构建可用。可以通过以下方式安装:
12+
13+
```shell
14+
npm install @rollup/browser
15+
```
16+
17+
在你的脚本中,可以通过以下方式导入:
18+
19+
```js
20+
import { rollup } from '@rollup/browser';
21+
```
22+
23+
或者,你也可以从 CDN 导入,例如对于 ESM 构建:
24+
25+
```js
26+
import * as rollup from 'https://unpkg.com/@rollup/browser/dist/es/rollup.browser.js';
27+
```
28+
29+
对于 UMD 构建:
30+
31+
```html
32+
<script src="https://unpkg.com/@rollup/browser/dist/rollup.browser.js"></script>
33+
```
34+
35+
这将创建一个全局变量 `window.rollup`。请注意,在每种情况下,你需要确保 `@rollup/browser` 包中的 `dist/bindings_wasm_bg.wasm` 文件与浏览器构建一起提供。
36+
37+
由于浏览器构建无法访问文件系统,你需要提供一个 [内存文件系统](#using-an-in-memory-file-system) 通过 [`fs`](../configuration-options/index.md#fs) 选项,或者你需要提供 [插件](#using-plugins-to-resolve-and-load-modules) 来解析和加载所有你想要打包的模块。
38+
39+
## 使用内存文件系统 {#using-an-in-memory-file-system}
40+
41+
Rollup 允许你提供一个内存文件系统实现,该实现需要实现 NodeJS `fs` API 的至少一个子集,参见 [`fs`](../configuration-options/index.md#fs) 选项。这使得浏览器构建的行为非常类似于 NodeJS 构建,甚至允许你使用某些依赖于文件系统的插件,前提是它们只能通过 [`this.fs`](../plugin-development/index.md#this-fs) 插件上下文属性访问它。下面是一个使用 [`memfs`](https://www.npmjs.com/package/memfs) 的示例:
42+
43+
```js twoslash
44+
/** @type {import('rollup')} */
45+
var rollup;
46+
// ---cut---
47+
import { rollup } from '@rollup/browser';
48+
import { Volume } from 'memfs';
49+
50+
const vol = Volume.fromJSON({
51+
'/main.js': "import foo from 'foo.js'; console.log(foo);",
52+
'/foo.js': 'export default 42;'
53+
});
54+
55+
rollup
56+
.rollup({
57+
input: '/main.js',
58+
fs: vol.promises
59+
})
60+
.then(bundle => bundle.generate({ format: 'es' }))
61+
.then(({ output }) => console.log(output[0].code));
62+
```
63+
64+
## 使用插件解析和加载模块 {#using-plugins-to-resolve-and-load-modules}
65+
66+
你也可以通过插件解析和加载所有模块。下面是一个示例:
67+
68+
```js twoslash
69+
/** @type {import('rollup')} */
70+
var rollup;
71+
// ---cut---
72+
const modules = {
73+
'main.js': "import foo from 'foo.js'; console.log(foo);",
74+
'foo.js': 'export default 42;'
75+
};
76+
77+
rollup
78+
.rollup({
79+
input: 'main.js',
80+
plugins: [
81+
{
82+
name: 'loader',
83+
resolveId(source) {
84+
if (modules.hasOwnProperty(source)) {
85+
return source;
86+
}
87+
},
88+
load(id) {
89+
if (modules.hasOwnProperty(id)) {
90+
return modules[id];
91+
}
92+
}
93+
}
94+
]
95+
})
96+
.then(bundle => bundle.generate({ format: 'es' }))
97+
.then(({ output }) => console.log(output[0].code));
98+
```
99+
100+
这个示例只支持两个导入,`"main.js"``"foo.js"`,并且不支持相对导入。下面是一个使用绝对 URL 作为入口文件并支持相对导入的示例。在这种情况下,我们只是重新打包 Rollup 本身,但它可以用于任何其他暴露 ES 模块的 URL:
101+
102+
```js twoslash
103+
/** @type {import('rollup')} */
104+
var rollup;
105+
// ---cut---
106+
rollup
107+
.rollup({
108+
input: 'https://unpkg.com/rollup/dist/es/rollup.js',
109+
plugins: [
110+
{
111+
name: 'url-resolver',
112+
resolveId(source, importer) {
113+
if (source[0] !== '.') {
114+
try {
115+
new URL(source);
116+
// If it is a valid URL, return it
117+
return source;
118+
} catch {
119+
// Otherwise make it external
120+
return { id: source, external: true };
121+
}
122+
}
123+
return new URL(source, importer).href;
124+
},
125+
async load(id) {
126+
const response = await fetch(id);
127+
return response.text();
128+
}
129+
}
130+
]
131+
})
132+
.then(bundle => bundle.generate({ format: 'es' }))
133+
.then(({ output }) => console.log(output));
134+
```

docs/command-line-interface/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ export default {
139139
clearScreen,
140140
exclude,
141141
include,
142-
skipWrite
142+
skipWrite,
143+
allowInputInsideOutputPath
143144
}
144145
};
145146
```
@@ -459,6 +460,7 @@ export default {
459460
--no-treeshake.unknownGlobalSideEffects 假设未知的全局变量不会抛出异常
460461
--validate 验证输出
461462
--waitForBundleInput 等待打包输入文件
463+
--watch.allowInputInsideOutputPath 输入路径是否允许是输出路径的子路径
462464
--watch.buildDelay <number> 节流观察重建
463465
--no-watch.clearScreen 重建时不要清除屏幕
464466
--watch.exclude <files> 排除要观察的文件

0 commit comments

Comments
 (0)