Visitar URL original
docs(options): add description for input options · rolldown/rolldown@3840b83 · GitHub
Skip to content

Commit 3840b83

Browse files
committed
docs(options): add description for input options
1 parent 435c3fb commit 3840b83

17 files changed

Lines changed: 354 additions & 101 deletions

‎.oxlintrc.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"jsdoc/check-tag-names": [
2525
"error",
2626
{
27-
"definedTags": ["category", "include"]
27+
"definedTags": ["category", "include", "experimental", "inline"]
2828
}
2929
],
3030
"no-unused-expressions": [

‎packages/rolldown/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import type {
1616
} from './log/logging';
1717
import type { ChecksOptions } from './options/generated/checks-options';
1818
import type {
19+
ExternalOptionFunction,
1920
ExternalOption,
2021
InputOption,
2122
InputOptions,
2223
ModuleTypes,
2324
OptimizationOptions,
2425
WatcherOptions,
2526
} from './options/input-options';
27+
import type { TransformOptions } from './options/transform-options';
2628
import type { NormalizedInputOptions } from './options/normalized-input-options';
2729
import type {
2830
InternalModuleFormat,
@@ -118,13 +120,15 @@ export type {
118120
EmittedFile,
119121
EmittedPrebuiltChunk,
120122
ExistingRawSourceMap,
123+
ExternalOptionFunction,
121124
ExternalOption,
122125
FunctionPluginHooks,
123126
GeneralHookFilter,
124127
GeneratedCodeOptions,
125128
GeneratedCodePreset,
126129
GetModuleInfo,
127130
GlobalsFunction,
131+
TransformOptions,
128132
HookFilter,
129133
HookFilterExtension,
130134
ImportKind,

‎packages/rolldown/src/log/logging.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
/** @inline */
12
export type LogLevel = 'info' | 'debug' | 'warn';
3+
/** @inline */
24
export type LogLevelOption = LogLevel | 'silent';
5+
/** @inline */
36
type LogLevelWithError = LogLevel | 'error';
47

58
export interface RollupLog {
@@ -27,6 +30,7 @@ export interface RollupLog {
2730
url?: string;
2831
}
2932

33+
/** @inline */
3034
export type RollupLogWithString = RollupLog | string;
3135

3236
/** @category Plugin APIs */
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
#### In-depth
22

3-
The `context` option controls what `this` refers to in the top-level scope of your bundled code. This is particularly important for:
3+
The `context` option controls what `this` refers to in the top-level scope of the input modules.
44

5-
- **IIFE bundles** that need to access global objects
6-
- **UMD bundles** that run in multiple environments
7-
- **Code that references `this` at the top level**
5+
In ES modules, the `this` value is `undefined` by specification. This option allows you to set a different value. For example, if your input modules expects `this` to be `window` like in non-ES module scripts, you can set `context` to `'window'`.
86

9-
By default:
10-
11-
- For `'iife'` and `'umd'` formats on browser platform: `this` is `'window'`
12-
- For `'iife'` and `'umd'` formats on node platform: `this` is `'global'`
13-
- For ES modules: `this` is `undefined`
14-
15-
Using `'globalThis'` provides a cross-platform way to access the global object that works in both browser and Node.js environments.
7+
Note that if the input module is detected as CommonJS, Rolldown will use `exports` as the `this` value regardless of this option.

‎packages/rolldown/src/options/docs/external.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
The matched IDs should be either:
2+
3+
1. the name of an external dependency, exactly the way it is written in the import statement. I.e. to mark `import "dependency.js"` as external, use `"dependency.js"` while to mark `import "dependency"` as external, use `"dependency"`.
4+
1. a resolved ID (like an absolute path to a file).
5+
6+
When creating an `iife` or `umd` bundle, you will need to provide global variable names to replace your external imports via the [`output.globals`](/reference/OutputOptions.globals) option.
7+
18
#### Examples
29

310
##### String pattern

‎packages/rolldown/src/options/docs/input.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default defineConfig({
2323
input: {
2424
index: 'src/index.js',
2525
utils: 'src/utils/index.js',
26-
components: 'src/components/index.js',
26+
'components/Foo': 'src/components/Foo.js',
2727
},
2828
});
2929
```
@@ -33,3 +33,5 @@ export default defineConfig({
3333
`input` allows you to specify one or more [entries](/glossary/entry) with [names](/glossary/entry-name) for the bundling process.
3434

3535
When multiple entries are specified (either as an array or an object), Rolldown will create separate [entry chunks](/glossary/entry-chunk) for each entry.
36+
37+
The generated chunk names will follow the [`output.chunkFileNames`](/reference/OutputOptions.chunkFileNames) option. When using the object form, the `[name]` portion of the file name will be the name of the object property while for the array form, it will be the file name of the entry point. Note that it is possible when using the object form to put entry points into different sub-folders by adding a `/` to the name.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The default logLevel of "info" means that info and warnings logs will be processed while debug logs will be swallowed, which means that they are neither passed to plugin `onLog` hooks nor the `onLog` option or printed to the console.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
For true, an external import like `import "/Users/Rolldown/project/relative.js"` would be converted to a relative path. When converting an absolute path to a relative path, Rolldown does _not_ take the [`file`](/reference/OutputOptions.file) or [`dir`](/reference/OutputOptions.dir) options into account, because those may not be present e.g. for builds using the JavaScript API. Instead, it assumes that the root of the generated bundle is located at the common shared parent directory of all modules that were included in the bundle. Assuming that the common parent directory of all modules is `"/Users/Rolldown/project"`, the import from above would likely be converted to import `"./relative.js"` in the output. If the output chunk is itself nested in a subdirectory by choosing e.g. `chunkFileNames: "chunks/[name].js"`, the import would be `"../relative.js"`. As stated before, this would also apply to originally relative imports like `import "./relative.js"` that are resolved to an absolute path before they are marked as external by the [`external`](/reference/InputOptions.external) option.
2+
3+
One common problem is that this mechanism will also apply to imports like `import "/absolute.js'"`, resulting in unexpected relative paths in the output. For this case, `"ifRelativeSource"` checks if the original import was a relative import and only then convert it to a relative import in the output.
4+
5+
Choosing `false` will keep all paths as absolute paths in the output.
6+
7+
Note that when a relative path is directly marked as "external" using the [`external`](/reference/InputOptions.external) option, then it will be the same relative path in the output. When it is resolved first via a plugin or Rollup core and then marked as external, the above logic will apply.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This handler will not be invoked if logs are filtered out by the [`logLevel`](/reference/InputOptions.logLevel) option. I.e. by default, `"debug"` logs will be swallowed.
2+
3+
If the default handler is not invoked, the log will not be printed to the console. Moreover, you can change the log level by invoking the default handler with a different level. Using the additional level `"error"` will turn the log into a thrown error that has all properties of the log attached.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
To migrate from `onwarn` to `onLog`, check the `level` parameter to filter for warnings:
2+
3+
```js
4+
// Before: Using `onwarn`
5+
export default {
6+
onwarn(warning, defaultHandler) {
7+
// Suppress certain warnings
8+
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
9+
// Handle other warnings with default behavior
10+
defaultHandler(warning);
11+
},
12+
};
13+
```
14+
15+
```js
16+
// After: Using `onLog`
17+
export default {
18+
onLog(level, log, defaultHandler) {
19+
// Handle only warnings (same behavior as `onwarn`)
20+
if (level === 'warn') {
21+
// Suppress certain warnings
22+
if (log.code === 'CIRCULAR_DEPENDENCY') return;
23+
// Handle other warnings with default behavior
24+
defaultHandler(level, log);
25+
} else {
26+
// Let other log levels pass through
27+
defaultHandler(level, log);
28+
}
29+
},
30+
};
31+
```

0 commit comments

Comments
 (0)