Skip to content

Commit 8a3e032

Browse files
committed
feat: add Encore.configureDevServerOptions()
1 parent a4ae7ce commit 8a3e032

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,27 @@ class Encore {
652652
return this;
653653
}
654654

655+
/**
656+
* Configure the devServer configuration.
657+
*
658+
* https://webpack.js.org/configuration/dev-server
659+
*
660+
* ```
661+
* Encore.configureDevServerOptions(function(options) {
662+
* // change the configuration
663+
* options
664+
* });
665+
* ```
666+
*
667+
* @param {function} callback
668+
* @returns {Encore}
669+
*/
670+
configureDevServerOptions(callback) {
671+
webpackConfig.configureDevServerOptions(callback);
672+
673+
return this;
674+
}
675+
655676
/**
656677
* Automatically make some variables available everywhere!
657678
*

lib/WebpackConfig.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class WebpackConfig {
144144
this.cssLoaderConfigurationCallback = () => {};
145145
this.splitChunksConfigurationCallback = () => {};
146146
this.watchOptionsConfigurationCallback = () => {};
147+
this.devServerOptionsConfigurationCallback = () => {};
147148
this.vueLoaderOptionsCallback = () => {};
148149
this.eslintLoaderOptionsCallback = () => {};
149150
this.tsConfigurationCallback = () => {};
@@ -499,6 +500,14 @@ class WebpackConfig {
499500
this.watchOptionsConfigurationCallback = callback;
500501
}
501502

503+
configureDevServerOptions(callback) {
504+
if (typeof callback !== 'function') {
505+
throw new Error('Argument 1 to configureDevServerOptions() must be a callback function.');
506+
}
507+
508+
this.devServerOptionsConfigurationCallback = callback;
509+
}
510+
502511
createSharedEntry(name, file) {
503512
if (this.shouldSplitEntryChunks) {
504513
throw new Error('Using splitEntryChunks() and createSharedEntry() together is not supported. Use one of these strategies only to optimize your build.');

lib/config-generator.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ class ConfigGenerator {
613613
buildDevServerConfig() {
614614
const contentBase = pathUtil.getContentBase(this.webpackConfig);
615615

616-
return {
616+
const devServerOptions = {
617617
contentBase: contentBase,
618618
// this doesn't appear to be necessary, but here in case
619619
publicPath: this.webpackConfig.getRealPublicPath(),
@@ -627,6 +627,11 @@ class ConfigGenerator {
627627
watchOptions: this.buildWatchOptionsConfig(),
628628
https: this.webpackConfig.useDevServerInHttps()
629629
};
630+
631+
return applyOptionsCallback(
632+
this.webpackConfig.devServerOptionsConfigurationCallback,
633+
devServerOptions
634+
);
630635
}
631636
}
632637

0 commit comments

Comments
 (0)