Skip to content

Commit ceae261

Browse files
committed
docs(en): merging all conflicts
2 parents 085f418 + 72858cb commit ceae261

File tree

60 files changed

+1306
-467
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

+1306
-467
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: 'Running Rollup in a Browser'
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: Running Rollup in a Browser
3+
---
4+
5+
# {{ $frontmatter.title }}
6+
7+
[[toc]]
8+
9+
## The browser build
10+
11+
While the regular Rollup build relies on some NodeJS builtin libraries, there is also a browser build available that only uses browser APIs. You can install it via
12+
13+
```shell
14+
npm install @rollup/browser
15+
```
16+
17+
and in your script, import it via
18+
19+
```js
20+
import { rollup } from '@rollup/browser';
21+
```
22+
23+
Alternatively, you can import from a CDN, e.g. for the ESM build
24+
25+
```js
26+
import * as rollup from 'https://unpkg.com/@rollup/browser/dist/es/rollup.browser.js';
27+
```
28+
29+
and for the UMD build
30+
31+
```html
32+
<script src="https://unpkg.com/@rollup/browser/dist/rollup.browser.js"></script>
33+
```
34+
35+
which will create a global variable `window.rollup`. Note that in each case, you need to make sure that the file `dist/bindings_wasm_bg.wasm` from the `@rollup/browser` package is served next to where the browser build is served.
36+
37+
As the browser build cannot access the file system, you either need to provide an [in-memory file system](#using-an-in-memory-file-system) via the [`fs`](../configuration-options/index.md#fs) option, or you need to [provide plugins](#using-plugins-to-resolve-and-load-modules) that resolve and load all modules you want to bundle.
38+
39+
## Using an in-memory file system
40+
41+
Rollup allows you to provide an in-memory file system implementation that needs to implement at least a certain sub-set of the NodeJS `fs` API, cf. the [`fs`](../configuration-options/index.md#fs) option. This makes the browser build behave very similar to the NodeJS build and even allows you to use certain plugins that rely on the file system, provided they only access it via the [`this.fs`](../plugin-development/index.md#this-fs) plugin context property. Here is an example that uses [`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+
You can also resolve and load all modules via plugins. Here is how you could do this:
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+
This example only supports two imports, `"main.js"` and `"foo.js"`, and no relative imports. Here is another example that uses absolute URLs as entry points and supports relative imports. In that case, we are just re-bundling Rollup itself, but it could be used on any other URL that exposes an ES module:
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+
```

0 commit comments

Comments
 (0)