Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Export defineConfig defines the auxiliary function of the configuration #4127

Merged
merged 3 commits into from Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/01-command-line-reference.md
Expand Up @@ -200,6 +200,33 @@ export default commandLineArgs => {
}
```

Config Intellisense
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make this a #### sub-heading so that it looks right on the web site

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise looks great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added: 555cac3


Since Rollup ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints:

```javascript
// rollup.config.js
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
// ...
}

export default config
```

Alternatively you can use the helper which should provide intellisense without the need for jsdoc annotations:defineConfig

```javascript
// rollup.config.js
import { defineConfig } from 'rollup'

export default defineConfig({
// ...
})
```

### Differences to the JavaScript API

While config files provide an easy way to configure Rollup, they also limit how Rollup can be invoked and where configuration is taken from. Especially if you are rebundling Rollup in another build tool or want to integrate it into an advanced build process, it may be better to directly invoke Rollup programmatically from your scripts.
Expand Down
10 changes: 10 additions & 0 deletions src/rollup/rollup.ts
Expand Up @@ -20,6 +20,7 @@ import {
OutputOptions,
Plugin,
RollupBuild,
RollupOptions,
RollupOutput,
RollupWatcher
} from './types';
Expand Down Expand Up @@ -282,3 +283,12 @@ function writeOutputFile(

return Promise.all([writeFile(fileName, source), writeSourceMapPromise]);
}

/**
* Auxiliary function for defining rollup configuration
* Mainly to facilitate IDE code prompts, after all, export default does not prompt, even if you add @type annotations, it is not accurate
* @param options
*/
export function defineConfig<T extends RollupOptions | RollupOptions[]>(options: T): T {
return options;
}
3 changes: 3 additions & 0 deletions src/rollup/types.d.ts
Expand Up @@ -883,3 +883,6 @@ interface AcornNode {
start: number;
type: string;
}

export function defineConfig(options: RollupOptions): RollupOptions;
export function defineConfig(options: RollupOptions[]): RollupOptions[];