-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
177 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Configuration as RspackConfiguration } from '@rspack/core'; | ||
import type { Configuration as WebpackConfiguration } from 'webpack'; | ||
import type { EnvironmentContext } from '../types'; | ||
|
||
type BundlerType = 'rspack' | 'webpack'; | ||
type BundlerConfig = RspackConfiguration | WebpackConfiguration; | ||
|
||
export interface ModifyBundlerConfigOption { | ||
environment: EnvironmentContext; | ||
type: BundlerType; | ||
} | ||
|
||
type ModifyConfigFn = ( | ||
config: BundlerConfig, | ||
options: ModifyBundlerConfigOption, | ||
) => Promise<BundlerConfig | void> | void | BundlerConfig; | ||
|
||
export type OnGetBundlerConfig = (cb: ModifyConfigFn) => void; | ||
|
||
class BundlerConfigContext { | ||
private modifyConfigFns: ModifyConfigFn[] = []; | ||
|
||
onGetBundlerConfig(cb: ModifyConfigFn) { | ||
this.modifyConfigFns.push(cb); | ||
} | ||
|
||
async runOnGetBundlerConfig(config: BundlerConfig, options: ModifyBundlerConfigOption) { | ||
for (const fn of this.modifyConfigFns) { | ||
const result = await fn(config, options); | ||
if (result) { | ||
config = result; | ||
} | ||
} | ||
return config; | ||
} | ||
} | ||
|
||
export const bundlerConfigContext = new BundlerConfigContext(); | ||
|
||
export const onGetBundlerConfig: OnGetBundlerConfig = | ||
bundlerConfigContext.onGetBundlerConfig.bind(bundlerConfigContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { TaskConfig } from 'build-scripts'; | ||
import type { Config, EnvironmentContext } from '../types'; | ||
|
||
interface ModifyEnvironmentConfigOption { | ||
environment: EnvironmentContext; | ||
} | ||
|
||
export type OnGetEnvironmentConfig = (cb: ModifyEnvironmentConfigFn) => void; | ||
|
||
type ModifyEnvironmentConfigFn = ( | ||
config: Config, | ||
options: ModifyEnvironmentConfigOption, | ||
) => Promise<Config | void> | void | Config; | ||
|
||
class EnvironmentConfigContext { | ||
private modifyConfigFns: ModifyEnvironmentConfigFn[] = []; | ||
|
||
onGetEnvironmentConfig(cb: ModifyEnvironmentConfigFn) { | ||
this.modifyConfigFns.push(cb); | ||
} | ||
|
||
async runOnGetEnvironmentConfig(taskConfigs: TaskConfig<Config>[]) { | ||
for (const fn of this.modifyConfigFns) { | ||
taskConfigs.forEach(async (taskConfig) => { | ||
const result = await fn(taskConfig.config, { environment: { name: taskConfig.name } }); | ||
if (result) { | ||
taskConfig.config = result; | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export const environmentConfigContext = new EnvironmentConfigContext(); | ||
export const onGetEnvironmentConfig: OnGetEnvironmentConfig = | ||
environmentConfigContext.onGetEnvironmentConfig.bind(environmentConfigContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { UserConfig } from './userConfig'; | ||
|
||
type EnvironmentNotSupportConfig = Omit< | ||
UserConfig, | ||
| 'server' | ||
| 'configureWebpack' | ||
| 'webpack' | ||
| 'routes' | ||
| 'eslint' | ||
| 'tsChecker' | ||
| 'ssr' | ||
| 'ssg' | ||
| 'optimization' | ||
| 'mock' | ||
| 'plugins' | ||
>; | ||
|
||
export type EnvironmentUserConfig = Record<string, EnvironmentNotSupportConfig>; | ||
|
||
export interface EnvironmentContext { | ||
name: string; | ||
// dependencies: Set<string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters