Skip to content

Commit dbe8d39

Browse files
committed
feat: implement dev-server watchOptions configuration
1 parent 70f47f6 commit dbe8d39

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,27 @@ class Encore {
588588
return this;
589589
}
590590

591+
/**
592+
* Configure the devServer.watchOptions configuration, only when the dev server is running.
593+
*
594+
* https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
595+
* https://webpack.js.org/configuration/watch/
596+
*
597+
* Encore.configureDevServerWatchOptions(function(watchOptions) {
598+
* // change the configuration
599+
*
600+
* watchOptions.poll = 250;
601+
* });
602+
*
603+
* @param {function} callback
604+
* @returns {Encore}
605+
*/
606+
configureDevServerWatchOptions(callback) {
607+
webpackConfig.configureDevServerWatchOptions(callback);
608+
609+
return this;
610+
}
611+
591612
/**
592613
* Automatically make some variables available everywhere!
593614
*

lib/WebpackConfig.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class WebpackConfig {
9494
this.shouldUseSingleRuntimeChunk = null;
9595
this.shouldSplitEntryChunks = false;
9696
this.splitChunksConfigurationCallback = () => {};
97+
this.devServerWatchOptionsConfigurationCallback = () => {};
9798
this.vueLoaderOptionsCallback = () => {};
9899
this.eslintLoaderOptionsCallback = () => {};
99100
this.tsConfigurationCallback = () => {};
@@ -395,6 +396,14 @@ class WebpackConfig {
395396
this.splitChunksConfigurationCallback = callback;
396397
}
397398

399+
configureDevServerWatchOptions(callback) {
400+
if (typeof callback !== 'function') {
401+
throw new Error('Argument 1 to configureDevServerWatchOptions() must be a callback function.');
402+
}
403+
404+
this.devServerWatchOptionsConfigurationCallback = callback;
405+
}
406+
398407
createSharedEntry(name, file) {
399408
if (this.shouldSplitEntryChunks) {
400409
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,11 @@ class ConfigGenerator {
527527

528528
buildDevServerConfig() {
529529
const contentBase = pathUtil.getContentBase(this.webpackConfig);
530+
const watchOptions = {
531+
ignored: /node_modules/
532+
};
533+
534+
this.webpackConfig.devServerWatchOptionsConfigurationCallback(watchOptions);
530535

531536
return {
532537
contentBase: contentBase,
@@ -539,9 +544,7 @@ class ConfigGenerator {
539544
quiet: true,
540545
compress: true,
541546
historyApiFallback: true,
542-
watchOptions: {
543-
ignored: /node_modules/
544-
},
547+
watchOptions: watchOptions,
545548
https: this.webpackConfig.useDevServerInHttps()
546549
};
547550
}

0 commit comments

Comments
 (0)