From 2593da398aa14c16d1601aa4b173db33dc58694b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Sun, 6 Jun 2021 13:07:18 +0800 Subject: [PATCH 1/3] feat: Export defineConfig defines the auxiliary function of the configuration --- src/rollup/rollup.ts | 10 ++++++++++ src/rollup/types.d.ts | 3 +++ 2 files changed, 13 insertions(+) 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[]; From 5d68a031143358ff84f6f91676af09061ed93a65 Mon Sep 17 00:00:00 2001 From: rxliuli Date: Sun, 6 Jun 2021 13:15:22 +0800 Subject: [PATCH 2/3] docs: Add some documentation for `defineConfig` --- docs/01-command-line-reference.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index 659e7f0ba42..7f8b558e1e2 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. From 555cac31aa8cbf61c3a17b4c47e33bde720bfb5a Mon Sep 17 00:00:00 2001 From: rxliuli Date: Sun, 6 Jun 2021 13:33:41 +0800 Subject: [PATCH 3/3] docs: Set `Config Intellisense` as the fourth-level heading Refer to: https://github.com/rollup/rollup/pull/4127/files/5d68a031143358ff84f6f91676af09061ed93a65 --- docs/01-command-line-reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/01-command-line-reference.md b/docs/01-command-line-reference.md index 7f8b558e1e2..919ddc591c2 100755 --- a/docs/01-command-line-reference.md +++ b/docs/01-command-line-reference.md @@ -200,7 +200,7 @@ export default commandLineArgs => { } ``` -Config Intellisense +#### Config Intellisense Since Rollup ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints: