Skip to content

Commit

Permalink
feat: add extendRollupConfig option
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Mar 19, 2019
1 parent bbc4902 commit 9536a51
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
35 changes: 8 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import stringWidth from 'string-width'
import {
rollup,
watch,
InputOptions,
OutputOptions,
Plugin as RollupPlugin,
ModuleFormat as RollupFormat
} from 'rollup'
Expand All @@ -32,7 +30,9 @@ import {
ConfigEntryObject,
Env,
ConfigOutput,
FileNameContext
RunContext,
RollupConfig,
Task
} from './types'

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

interface RunContext {
unresolved: Set<string>
}

interface Task {
title: string
getConfig(context: RunContext, task: Task): Promise<RollupConfigOutput>
}

interface RollupInputConfig extends InputOptions {
plugins: Array<RollupPlugin>
}

interface RollupOutputConfig extends OutputOptions {
dir: string
}

interface RollupConfigOutput {
inputConfig: RollupInputConfig
outputConfig: RollupOutputConfig
}

interface RollupConfigInput {
source: {
input: string[] | ConfigEntryObject
Expand Down Expand Up @@ -171,7 +149,7 @@ export class Bundler {
context,
assets,
config
}: RollupConfigInput): Promise<RollupConfigOutput> {
}: RollupConfigInput): Promise<RollupConfig> {
// Always minify if config.minify is truthy
// Otherwise infer by format
const minify =
Expand Down Expand Up @@ -560,14 +538,17 @@ export class Bundler {
format
})
: this.config
return this.createRollupConfig({
const rollupConfig = await this.createRollupConfig({
source,
format,
title: task.title,
context,
assets,
config
})
return this.config.extendRollupConfig
? this.config.extendRollupConfig(rollupConfig)
: rollupConfig
}
})
}
Expand Down
39 changes: 38 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ModuleFormat as RollupFormat } from 'rollup'
import {
ModuleFormat as RollupFormat,
InputOptions,
OutputOptions,
Plugin as RollupPlugin
} from 'rollup'

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

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

export interface RunContext {
unresolved: Set<string>
}

export interface Task {
title: string
getConfig(context: RunContext, task: Task): Promise<RollupConfig>
}

export interface RollupInputConfig extends InputOptions {
plugins: Array<RollupPlugin>
}

export interface RollupOutputConfig extends OutputOptions {
dir: string
}

export interface RollupConfig {
inputConfig: RollupInputConfig
outputConfig: RollupOutputConfig
}

export type ExtendRollupConfig = (config: RollupConfig) => RollupConfig

export interface FileNameContext {
format: RollupFormat
minify: boolean
Expand Down Expand Up @@ -252,7 +281,14 @@ export interface Config {
* Configure the default babel preset
*/
babel?: BabelPresetOptions
/**
* Extending Bili config
*/
extendConfig?: ExtendConfig
/**
* Extending generated rollup config
*/
extendRollupConfig?: ExtendRollupConfig
}

interface ConfigOutputOverwrite {
Expand Down Expand Up @@ -280,6 +316,7 @@ export interface NormalizedConfig {
banner?: Banner
babel: BabelPresetOptions
extendConfig?: ExtendConfig
extendRollupConfig?: ExtendRollupConfig
}

export interface Options {
Expand Down

0 comments on commit 9536a51

Please sign in to comment.