Skip to content

Commit bc49419

Browse files
committed
Apply watchOptions to webpack config too, not only the dev server
1 parent e6eb6e1 commit bc49419

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,12 @@ class Encore {
589589
}
590590

591591
/**
592-
* Configure the devServer.watchOptions configuration, only when the dev server is running.
592+
* Configure the watchOptions and devServer.watchOptions configuration.
593593
*
594-
* https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
595594
* https://webpack.js.org/configuration/watch/
595+
* https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
596596
*
597-
* Encore.configureDevServerWatchOptions(function(watchOptions) {
597+
* Encore.configureWatchOptions(function(watchOptions) {
598598
* // change the configuration
599599
*
600600
* watchOptions.poll = 250; // useful when running inside a Virtual Machine
@@ -603,8 +603,8 @@ class Encore {
603603
* @param {function} callback
604604
* @returns {Encore}
605605
*/
606-
configureDevServerWatchOptions(callback) {
607-
webpackConfig.configureDevServerWatchOptions(callback);
606+
configureWatchOptions(callback) {
607+
webpackConfig.configureWatchOptions(callback);
608608

609609
return this;
610610
}

lib/WebpackConfig.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class WebpackConfig {
9494
this.shouldUseSingleRuntimeChunk = null;
9595
this.shouldSplitEntryChunks = false;
9696
this.splitChunksConfigurationCallback = () => {};
97-
this.devServerWatchOptionsConfigurationCallback = () => {};
97+
this.watchOptionsConfigurationCallback = () => {};
9898
this.vueLoaderOptionsCallback = () => {};
9999
this.eslintLoaderOptionsCallback = () => {};
100100
this.tsConfigurationCallback = () => {};
@@ -396,12 +396,12 @@ class WebpackConfig {
396396
this.splitChunksConfigurationCallback = callback;
397397
}
398398

399-
configureDevServerWatchOptions(callback) {
399+
configureWatchOptions(callback) {
400400
if (typeof callback !== 'function') {
401-
throw new Error('Argument 1 to configureDevServerWatchOptions() must be a callback function.');
401+
throw new Error('Argument 1 to configureWatchOptions() must be a callback function.');
402402
}
403403

404-
this.devServerWatchOptionsConfigurationCallback = callback;
404+
this.watchOptionsConfigurationCallback = callback;
405405
}
406406

407407
createSharedEntry(name, file) {

lib/config-generator.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class ConfigGenerator {
6969
rules: this.buildRulesConfig(),
7070
},
7171
plugins: this.buildPluginsConfig(),
72-
optimization: this.buildOptimizationConfig()
72+
optimization: this.buildOptimizationConfig(),
73+
watchOptions: this.buildWatchOptionsConfig()
7374
};
7475

7576
if (this.webpackConfig.useSourceMaps) {
@@ -525,13 +526,18 @@ class ConfigGenerator {
525526
return stats;
526527
}
527528

528-
buildDevServerConfig() {
529-
const contentBase = pathUtil.getContentBase(this.webpackConfig);
529+
buildWatchOptionsConfig() {
530530
const watchOptions = {
531531
ignored: /node_modules/
532532
};
533533

534-
this.webpackConfig.devServerWatchOptionsConfigurationCallback(watchOptions);
534+
this.webpackConfig.watchOptionsConfigurationCallback(watchOptions);
535+
536+
return watchOptions;
537+
}
538+
539+
buildDevServerConfig() {
540+
const contentBase = pathUtil.getContentBase(this.webpackConfig);
535541

536542
return {
537543
contentBase: contentBase,
@@ -544,7 +550,7 @@ class ConfigGenerator {
544550
quiet: true,
545551
compress: true,
546552
historyApiFallback: true,
547-
watchOptions: watchOptions,
553+
watchOptions: this.buildWatchOptionsConfig(),
548554
https: this.webpackConfig.useDevServerInHttps()
549555
};
550556
}

test/WebpackConfig.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,28 +1066,28 @@ describe('WebpackConfig object', () => {
10661066
});
10671067
});
10681068

1069-
describe('configureDevServerWatchOptions()', () => {
1069+
describe('configureWatchOptions()', () => {
10701070
it('Pass config', () => {
10711071
const config = createConfig();
10721072
const callback = (watchOptions) => {
10731073
watchOptions.poll = 250;
10741074
};
10751075

1076-
config.configureDevServerWatchOptions(callback);
1076+
config.configureWatchOptions(callback);
10771077

1078-
expect(config.devServerWatchOptionsConfigurationCallback).to.equal(callback);
1078+
expect(config.watchOptionsConfigurationCallback).to.equal(callback);
10791079
});
10801080

10811081
it('Call method without a valid callback', () => {
10821082
const config = createConfig();
10831083

10841084
expect(() => {
1085-
config.configureDevServerWatchOptions();
1086-
}).to.throw('Argument 1 to configureDevServerWatchOptions() must be a callback function.');
1085+
config.configureWatchOptions();
1086+
}).to.throw('Argument 1 to configureWatchOptions() must be a callback function.');
10871087

10881088
expect(() => {
1089-
config.configureDevServerWatchOptions({});
1090-
}).to.throw('Argument 1 to configureDevServerWatchOptions() must be a callback function.');
1089+
config.configureWatchOptions({});
1090+
}).to.throw('Argument 1 to configureWatchOptions() must be a callback function.');
10911091
});
10921092
});
10931093
});

test/config-generator.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,15 @@ describe('The config-generator function', () => {
583583
config.setPublicPath('/');
584584
config.addEntry('main', './main');
585585

586-
config.configureDevServerWatchOptions(watchOptions => {
586+
config.configureWatchOptions(watchOptions => {
587587
watchOptions.poll = 250;
588588
});
589589

590590
const actualConfig = configGenerator(config);
591+
expect(actualConfig.watchOptions).to.deep.equals({
592+
'ignored': /node_modules/,
593+
'poll': 250,
594+
});
591595
expect(actualConfig.devServer.watchOptions).to.deep.equals({
592596
'ignored': /node_modules/,
593597
'poll': 250,
@@ -954,4 +958,21 @@ describe('The config-generator function', () => {
954958
expect(JSON.stringify(logger.getMessages().deprecation)).to.contain('the recommended setting is Encore.enableSingleRuntimeChunk()');
955959
});
956960
});
961+
962+
describe('Test buildWatchOptionsConfig()', () => {
963+
it('Set webpack watch options', () => {
964+
const config = createConfig();
965+
config.outputPath = '/tmp/public/build';
966+
config.setPublicPath('/build/');
967+
config.configureWatchOptions(watchOptions => {
968+
watchOptions.poll = 250;
969+
});
970+
971+
const actualConfig = configGenerator(config);
972+
expect(actualConfig.watchOptions).to.deep.equals({
973+
ignored: /node_modules/,
974+
poll: 250,
975+
});
976+
});
977+
});
957978
});

0 commit comments

Comments
 (0)