Skip to content

Commit 9536a51

Browse files
committedMar 19, 2019
feat: add extendRollupConfig option
1 parent bbc4902 commit 9536a51

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed
 

‎src/index.ts

+8-27
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import stringWidth from 'string-width'
1010
import {
1111
rollup,
1212
watch,
13-
InputOptions,
14-
OutputOptions,
1513
Plugin as RollupPlugin,
1614
ModuleFormat as RollupFormat
1715
} from 'rollup'
@@ -32,7 +30,9 @@ import {
3230
ConfigEntryObject,
3331
Env,
3432
ConfigOutput,
35-
FileNameContext
33+
RunContext,
34+
RollupConfig,
35+
Task
3636
} from './types'
3737

3838
// Make rollup-plugin-vue use basename in component.__file instead of absolute path
@@ -45,28 +45,6 @@ interface RunOptions {
4545
concurrent?: boolean
4646
}
4747

48-
interface RunContext {
49-
unresolved: Set<string>
50-
}
51-
52-
interface Task {
53-
title: string
54-
getConfig(context: RunContext, task: Task): Promise<RollupConfigOutput>
55-
}
56-
57-
interface RollupInputConfig extends InputOptions {
58-
plugins: Array<RollupPlugin>
59-
}
60-
61-
interface RollupOutputConfig extends OutputOptions {
62-
dir: string
63-
}
64-
65-
interface RollupConfigOutput {
66-
inputConfig: RollupInputConfig
67-
outputConfig: RollupOutputConfig
68-
}
69-
7048
interface RollupConfigInput {
7149
source: {
7250
input: string[] | ConfigEntryObject
@@ -171,7 +149,7 @@ export class Bundler {
171149
context,
172150
assets,
173151
config
174-
}: RollupConfigInput): Promise<RollupConfigOutput> {
152+
}: RollupConfigInput): Promise<RollupConfig> {
175153
// Always minify if config.minify is truthy
176154
// Otherwise infer by format
177155
const minify =
@@ -560,14 +538,17 @@ export class Bundler {
560538
format
561539
})
562540
: this.config
563-
return this.createRollupConfig({
541+
const rollupConfig = await this.createRollupConfig({
564542
source,
565543
format,
566544
title: task.title,
567545
context,
568546
assets,
569547
config
570548
})
549+
return this.config.extendRollupConfig
550+
? this.config.extendRollupConfig(rollupConfig)
551+
: rollupConfig
571552
}
572553
})
573554
}

‎src/types.ts

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { ModuleFormat as RollupFormat } from 'rollup'
1+
import {
2+
ModuleFormat as RollupFormat,
3+
InputOptions,
4+
OutputOptions,
5+
Plugin as RollupPlugin
6+
} from 'rollup'
27

38
import { Banner } from './utils/get-banner'
49

@@ -35,6 +40,30 @@ export type ExtendConfig = (
3540
{ format, input }: { format: Format; input: string[] | ConfigEntryObject }
3641
) => NormalizedConfig
3742

43+
export interface RunContext {
44+
unresolved: Set<string>
45+
}
46+
47+
export interface Task {
48+
title: string
49+
getConfig(context: RunContext, task: Task): Promise<RollupConfig>
50+
}
51+
52+
export interface RollupInputConfig extends InputOptions {
53+
plugins: Array<RollupPlugin>
54+
}
55+
56+
export interface RollupOutputConfig extends OutputOptions {
57+
dir: string
58+
}
59+
60+
export interface RollupConfig {
61+
inputConfig: RollupInputConfig
62+
outputConfig: RollupOutputConfig
63+
}
64+
65+
export type ExtendRollupConfig = (config: RollupConfig) => RollupConfig
66+
3867
export interface FileNameContext {
3968
format: RollupFormat
4069
minify: boolean
@@ -252,7 +281,14 @@ export interface Config {
252281
* Configure the default babel preset
253282
*/
254283
babel?: BabelPresetOptions
284+
/**
285+
* Extending Bili config
286+
*/
255287
extendConfig?: ExtendConfig
288+
/**
289+
* Extending generated rollup config
290+
*/
291+
extendRollupConfig?: ExtendRollupConfig
256292
}
257293

258294
interface ConfigOutputOverwrite {
@@ -280,6 +316,7 @@ export interface NormalizedConfig {
280316
banner?: Banner
281317
babel: BabelPresetOptions
282318
extendConfig?: ExtendConfig
319+
extendRollupConfig?: ExtendRollupConfig
283320
}
284321

285322
export interface Options {

0 commit comments

Comments
 (0)
Please sign in to comment.