Skip to content

Commit

Permalink
Add documentation and ES build
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 26, 2023
1 parent 3b70384 commit 54e1bbd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
23 changes: 22 additions & 1 deletion docs/javascript-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const watchOptions = {

See above for details on `inputOptions` and `outputOptions`, or consult the [big list of options](../configuration-options/index.md) for info on `chokidar`, `include` and `exclude`.

### Programmatically loading a config file
## Programmatically loading a config file

In order to aid in generating such a config, rollup exposes the helper it uses to load config files in its command line interface via a separate entry-point. This helper receives a resolved `fileName` and optionally an object containing command line parameters:

Expand Down Expand Up @@ -315,3 +315,24 @@ loadConfigFile(path.resolve(__dirname, 'rollup.config.js'), {
rollup.watch(options);
});
```

## Applying advanced log filters

While the command line interface provides a powerful way to filter logs via the [`--filterLogs`](../command-line-interface/#filterlogs-filter) flag, this functionality is not directly available when using the JavaScript API. However, Rollup exposes a helper `getLogFilter` to generate filters using the same syntax as the CLI. This is useful when specifying a custom `onLog` handler and for third party systems that want to provide a similar filtering experience as Rollup CLI. This function accepts an array of strings. Note that it does not split up comma-separated lists of filters like the CLI does.

```js
// rollup.config.mjs
import { getLogFilter } from 'rollup/getLogFilter';

const logFilter = getLogFilter(['code:FOO', 'code:BAR']);

export default {
input: 'main.js',
output: { format: 'es' },
onLog(level, log, handler) {
if (logFilter(log)) {
handler(level, log);
}
}
};
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"./getLogFilter": {
"types": "./dist/getLogFilter.d.ts",
"require": "./dist/getLogFilter.js",
"default": "./dist/getLogFilter.js"
"import": "./dist/es/getLogFilter.js"
},
"./dist/*": "./dist/*"
}
Expand Down
5 changes: 4 additions & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ export default async function (

const esmBuild: RollupOptions = {
...commonJSBuild,
input: { 'rollup.js': 'src/node-entry.ts' },
input: {
'getLogFilter.js': 'src/utils/getLogFilter.ts',
'rollup.js': 'src/node-entry.ts'
},
output: {
...commonJSBuild.output,
dir: 'dist/es',
Expand Down

0 comments on commit 54e1bbd

Please sign in to comment.