Skip to content

Commit d879bc4

Browse files
author
haili.lhq
committed
feat: devserver support config wrapper
1 parent 531c37e commit d879bc4

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/node/webpack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export const watch = async (opts: any) => {
1010
await watchWebpack(opts);
1111
};
1212

13-
export const devServer = async (opts: any) => {
13+
export const devServer = async (opts: any, configWrapper?: (webpackConfig: any) => any) => {
1414
const { runWebpackDevServer } = await import('../utils/webpack-dev-server');
15-
await runWebpackDevServer(opts);
15+
await runWebpackDevServer(opts, configWrapper);
1616
};
1717

1818
export const dll = async (opts: any) => {

src/utils/webpack-dev-server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ const stats = {
4141
children: false,
4242
};
4343

44-
export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
44+
export const runWebpackDevServer = async (
45+
opts: IOptions<IExtraOptions>,
46+
configWrapper?: (webpackConfig: webpack.Configuration) => webpack.Configuration,
47+
) => {
4548
let webpackConfig = await getWebpackConfig(opts);
4649

4750
if (opts.pipeConfig) {
@@ -131,6 +134,10 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
131134
webpackConfig = smp.wrap(webpackConfig);
132135
}
133136

137+
if (configWrapper) {
138+
webpackConfig = configWrapper(webpackConfig);
139+
}
140+
134141
const compiler = webpack(webpackConfig);
135142

136143
const devServer = new WebpackDevServer(compiler as any, webpackDevServerConfig);

0 commit comments

Comments
 (0)