diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index 659e7f0ba42..919ddc591c2 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -200,6 +200,33 @@ export default commandLineArgs => { } ``` +#### Config Intellisense + +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. diff --git a/src/rollup/rollup.ts b/src/rollup/rollup.ts index 235439dcb29..721d26cd60e 100644 --- a/src/rollup/rollup.ts +++ b/src/rollup/rollup.ts @@ -20,6 +20,7 @@ import { OutputOptions, Plugin, RollupBuild, + RollupOptions, RollupOutput, RollupWatcher } from './types'; @@ -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(options: T): T { + return options; +} diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 00cc25bf187..cab04c563aa 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -883,3 +883,6 @@ interface AcornNode { start: number; type: string; } + +export function defineConfig(options: RollupOptions): RollupOptions; +export function defineConfig(options: RollupOptions[]): RollupOptions[];