Skip to content

Commit 275fb6f

Browse files
committed
feature #1125 Changing to support the "server" options object for webpack-dev-server (weaverryan)
This PR was squashed before being merged into the main branch. Discussion ---------- Changing to support the "server" options object for webpack-dev-server Follow up to #1118 and solves #1119. The new `server` object has existed since `webpack-dev-server` 4.4 webpack/webpack-dev-server#3940, and we already require 4.8. Support for the old `https` kept for now (with deprecations) to help people migrate. Commits ------- e0fb0ad Changing to support the "server" options object for webpack-dev-server
2 parents bff8c9e + e0fb0ad commit 275fb6f

File tree

6 files changed

+1512
-1402
lines changed

6 files changed

+1512
-1402
lines changed

index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,12 @@ class Encore {
709709
* ```
710710
* Encore.configureDevServerOptions(function(options) {
711711
* // change the configuration
712-
* options.https = {
713-
* key: '<your SSL cert key content>',
714-
* cert: '<your SSL cert content>',
712+
* options.server = {
713+
* type: 'https',
714+
* options: {
715+
* key: '<your SSL cert key content or path>',
716+
* cert: '<your SSL cert content or path>',
717+
* }
715718
* };
716719
* });
717720
* ```

lib/config-generator.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,22 @@ class ConfigGenerator {
6060
/*
6161
* An unfortunate situation where we need to configure the final runtime
6262
* config later in the process. The problem is that devServer https can
63-
* be activated with either a --https flag or by setting the devServer.https
64-
* config to an object or true. So, only at this moment can we determine
63+
* be activated with either a --server-type=https flag or by setting the devServer.server.type='https'
64+
* config to true. So, only at this moment can we determine
6565
* if https has been activated by either method.
6666
*/
67-
if (this.webpackConfig.useDevServer() && (devServerConfig.https || this.webpackConfig.runtimeConfig.devServerHttps)) {
67+
if (this.webpackConfig.useDevServer() &&
68+
(
69+
devServerConfig.https
70+
|| (devServerConfig.server && devServerConfig.server.type === 'https')
71+
|| this.webpackConfig.runtimeConfig.devServerHttps
72+
)) {
6873
this.webpackConfig.runtimeConfig.devServerFinalIsHttps = true;
74+
75+
if (devServerConfig.https) {
76+
logger.deprecation('The "https" option inside of configureDevServerOptions() is deprecated. Use "server = { type: \'https\' }" instead.');
77+
}
78+
6979
} else {
7080
this.webpackConfig.runtimeConfig.devServerFinalIsHttps = false;
7181
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@babel/preset-env": "^7.16.0",
3333
"@nuxt/friendly-errors-webpack-plugin": "^2.5.1",
3434
"assets-webpack-plugin": "7.0.*",
35-
"babel-loader": "^8.2.2",
35+
"babel-loader": "^8.2.5",
3636
"chalk": "^4.0.0",
3737
"clean-webpack-plugin": "^4.0.0",
3838
"css-loader": "^6.7.0",
@@ -55,7 +55,7 @@
5555
"devDependencies": {
5656
"@babel/eslint-parser": "^7.17.0",
5757
"@babel/plugin-proposal-class-properties": "^7.0.0",
58-
"@babel/plugin-transform-react-jsx": "^7.0.0",
58+
"@babel/plugin-transform-react-jsx": "^7.12.11",
5959
"@babel/preset-react": "^7.0.0",
6060
"@babel/preset-typescript": "^7.0.0",
6161
"@hotwired/stimulus": "^3.0.0",
@@ -83,7 +83,7 @@
8383
"less": "^4.0.0",
8484
"less-loader": "^10.0.0",
8585
"mocha": "^9.1.4",
86-
"postcss": "^8.1.0",
86+
"postcss": "^8.3.0",
8787
"postcss-loader": "^6.0.0",
8888
"preact": "^10.5.0",
8989
"preact-compat": "^3.17.0",

test/config-generator.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -669,18 +669,24 @@ describe('The config-generator function', () => {
669669
config.setPublicPath('/');
670670
config.addEntry('main', './main');
671671
config.configureDevServerOptions(options => {
672-
options.https = {
673-
key: 'https.key',
674-
cert: 'https.cert',
672+
options.server = {
673+
'type': 'https',
674+
options: {
675+
key: 'https.key',
676+
cert: 'https.cert',
677+
}
675678
};
676679
});
677680

678681
const actualConfig = configGenerator(config);
679682

680683
expect(actualConfig.devServer).to.containSubset({
681-
https: {
682-
key: 'https.key',
683-
cert: 'https.cert',
684+
server: {
685+
type: 'https',
686+
options: {
687+
key: 'https.key',
688+
cert: 'https.cert',
689+
}
684690
},
685691
});
686692

test/functional.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ describe('Functional tests using webpack', function() {
229229
config.addEntry('main', './js/code_splitting');
230230
config.addStyleEntry('font', './css/roboto_font.css');
231231
config.addStyleEntry('bg', './css/background_image.scss');
232-
config.setPublicPath('http://localhost:8090/assets');
232+
config.setPublicPath('http://127.0.0.1:8090/assets');
233233
config.enableSassLoader();
234234
config.setManifestKeyPrefix('assets');
235235

@@ -249,21 +249,21 @@ describe('Functional tests using webpack', function() {
249249
// check that the publicPath is set correctly
250250
webpackAssert.assertOutputFileContains(
251251
'runtime.js',
252-
'__webpack_require__.p = "http://localhost:8090/assets/";'
252+
'__webpack_require__.p = "http://127.0.0.1:8090/assets/";'
253253
);
254254

255255
webpackAssert.assertOutputFileContains(
256256
'bg.css',
257-
'http://localhost:8090/assets/images/symfony_logo.91beba37.png'
257+
'http://127.0.0.1:8090/assets/images/symfony_logo.91beba37.png'
258258
);
259259
webpackAssert.assertOutputFileContains(
260260
'font.css',
261-
'http://localhost:8090/assets/fonts/Roboto.e1dcc0db.woff2'
261+
'http://127.0.0.1:8090/assets/fonts/Roboto.e1dcc0db.woff2'
262262
);
263263
// manifest file has CDN in value
264264
webpackAssert.assertManifestPath(
265265
'assets/main.js',
266-
'http://localhost:8090/assets/main.js'
266+
'http://127.0.0.1:8090/assets/main.js'
267267
);
268268

269269
testSetup.requestTestPage(
@@ -292,7 +292,8 @@ describe('Functional tests using webpack', function() {
292292

293293
it('The devServer config loads successfully', (done) => {
294294
const config = createWebpackConfig('public/assets', 'dev-server', {
295-
port: '8090'
295+
port: '8090',
296+
host: '127.0.0.1',
296297
});
297298
config.addEntry('main', './js/code_splitting');
298299
config.addStyleEntry('font', './css/roboto_font.css');
@@ -304,17 +305,17 @@ describe('Functional tests using webpack', function() {
304305
// check that the publicPath is set correctly
305306
webpackAssert.assertOutputFileContains(
306307
'runtime.js',
307-
'__webpack_require__.p = "http://localhost:8090/assets/";'
308+
'__webpack_require__.p = "http://127.0.0.1:8090/assets/";'
308309
);
309310

310311
webpackAssert.assertOutputFileContains(
311312
'bg.css',
312-
'http://localhost:8090/assets/images/symfony_logo.91beba37.png'
313+
'http://127.0.0.1:8090/assets/images/symfony_logo.91beba37.png'
313314
);
314315
// manifest file has CDN in value
315316
webpackAssert.assertManifestPath(
316317
'assets/main.js',
317-
'http://localhost:8090/assets/main.js'
318+
'http://127.0.0.1:8090/assets/main.js'
318319
);
319320

320321
testSetup.requestTestPage(

0 commit comments

Comments
 (0)