Skip to content

Commit 8772124

Browse files
committed
Remove deprecated --https flag and devServerConfig.https option
1 parent 0c706d2 commit 8772124

File tree

9 files changed

+718
-294
lines changed

9 files changed

+718
-294
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This is a new major version that contains several backwards-compatibility breaks
2222
* Update @nuxt/friendly-errors-webpack-plugin to @kocal/friendly-errors-webpack-plugin, a maintained fork of the original plugin
2323
* Update webpack from ^5.74.0 to ^5.82.0
2424
* Update css-minimizer-webpack-plugin to ^8.0.0, see [release notes](https://github.com/webpack/css-minimizer-webpack-plugin/releases/tag/v8.0.0)
25+
* Remove deprecated `--https` flag and `devServerConfig.https` option for webpack-dev-server, use `--server-type https` or `configureDevServerOptions()` with `server: 'https'` instead
2526
* Finish removing Vue 2 support leftovers (JSX code path, `vue-jsx` feature, `version: 2` option, Vue 2 peer dependencies), which was forgotten during v5.0.0
2627

2728
## 5.3.0

lib/config-generator.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,17 @@ class ConfigGenerator {
5858
getWebpackConfig() {
5959
const devServerConfig = this.webpackConfig.useDevServer() ? this.buildDevServerConfig() : null;
6060
/*
61-
* An unfortunate situation where we need to configure the final runtime
62-
* config later in the process. The problem is that devServer https can
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
65-
* if https has been activated by either method.
61+
* We need to configure the final runtime config later in the process.
62+
* The devServer https can be activated by setting devServer.server to
63+
* 'https' or { type: 'https' }. Only at this point can we determine
64+
* if https has been activated.
6665
*/
6766
if (this.webpackConfig.useDevServer() &&
6867
(
69-
devServerConfig.https
70-
|| devServerConfig.server === 'https'
68+
devServerConfig.server === 'https'
7169
|| (typeof devServerConfig.server === 'object' && devServerConfig.server.type === 'https')
72-
|| this.webpackConfig.runtimeConfig.devServerHttps
7370
)) {
7471
this.webpackConfig.runtimeConfig.devServerFinalIsHttps = true;
75-
76-
if (devServerConfig.https) {
77-
logger.deprecation('The "https" option inside of configureDevServerOptions() is deprecated. Use "server = { type: \'https\' }" instead.');
78-
}
79-
8072
} else {
8173
this.webpackConfig.runtimeConfig.devServerFinalIsHttps = false;
8274
}
@@ -612,11 +604,6 @@ class ConfigGenerator {
612604
headers: { 'Access-Control-Allow-Origin': '*' },
613605
compress: true,
614606
historyApiFallback: true,
615-
// In webpack-dev-server v4 beta 0, liveReload always causes
616-
// the page to refresh, not allowing HMR to update the page.
617-
// This is somehow related to the "static" option, but it's
618-
// unknown if there is a better option.
619-
// See https://github.com/webpack/webpack-dev-server/issues/2893
620607
liveReload: false,
621608
// see https://github.com/symfony/webpack-encore/issues/931#issuecomment-784483725
622609
host: this.webpackConfig.runtimeConfig.devServerHost,

lib/config/RuntimeConfig.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class RuntimeConfig {
1717
this.environment = process.env.NODE_ENV ? process.env.NODE_ENV : 'dev';
1818

1919
this.useDevServer = false;
20-
this.devServerHttps = null;
2120
// see config-generator - getWebpackConfig()
2221
this.devServerFinalIsHttps = null;
2322
this.devServerHost = null;

lib/config/parse-runtime.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ module.exports = function(argv, cwd) {
4343
runtimeConfig.useDevServer = true;
4444
runtimeConfig.devServerKeepPublicPath = argv.keepPublicPath || false;
4545

46-
if (argv.https || argv.serverType === 'https') {
47-
runtimeConfig.devServerHttps = true;
48-
}
49-
5046
if (typeof argv.public === 'string') {
5147
runtimeConfig.devServerPublic = argv.public;
5248
}

test/bin/encore.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,74 @@ module.exports = Encore.getWebpackConfig();
284284
}, 5000);
285285
});
286286

287+
it('Run the webpack-dev-server with --server-type https', function(done) {
288+
testSetup.emptyTmpDir();
289+
const testDir = testSetup.createTestAppDir();
290+
291+
fs.writeFileSync(
292+
path.join(testDir, 'package.json'),
293+
`{
294+
"devDependencies": {
295+
"@symfony/webpack-encore": "*"
296+
}
297+
}`
298+
);
299+
300+
fs.writeFileSync(
301+
path.join(testDir, 'webpack.config.js'),
302+
`
303+
const Encore = require('../../index.js');
304+
Encore
305+
.enableSingleRuntimeChunk()
306+
.setOutputPath('build/')
307+
.setPublicPath('/build')
308+
.addEntry('main', './js/no_require')
309+
;
310+
311+
module.exports = Encore.getWebpackConfig();
312+
`
313+
);
314+
315+
const binPath = path.resolve(__dirname, '../', '../', 'bin', 'encore.js');
316+
const abortController = new AbortController();
317+
const node = spawn('node', [binPath, 'dev-server', '--server-type', 'https', `--context=${testDir}`], {
318+
cwd: testDir,
319+
env: Object.assign({}, process.env, { NO_COLOR: 'true' }),
320+
signal: abortController.signal
321+
});
322+
323+
let stdout = '';
324+
let stderr = '';
325+
326+
node.stdout.on('data', (data) => {
327+
stdout += data.toString();
328+
});
329+
330+
node.stderr.on('data', (data) => {
331+
stderr += data.toString();
332+
});
333+
334+
node.on('error', (error) => {
335+
if (error.name !== 'AbortError') {
336+
throw new Error('Error executing encore', { cause: error });
337+
}
338+
339+
expect(stdout).to.contain('Running webpack-dev-server ...');
340+
expect(stdout).to.contain('Compiled successfully in');
341+
expect(stdout).to.contain('webpack compiled successfully');
342+
343+
expect(stderr).to.contain('[webpack-dev-server] Project is running at:');
344+
expect(stderr).to.contain('[webpack-dev-server] Loopback: https://localhost:8080/');
345+
expect(stderr).to.contain('[webpack-dev-server] Content not from webpack is served from');
346+
347+
done();
348+
});
349+
350+
setTimeout(() => {
351+
abortController.abort();
352+
}, 5000);
353+
});
354+
287355
describe('Without webpack-dev-server installed', function() {
288356
before(function() {
289357
execSync('yarn remove webpack-dev-server --dev', { cwd: projectDir });

test/config-generator.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,15 @@ describe('The config-generator function', function() {
590590
expect(config.runtimeConfig.devServerFinalIsHttps).is.false;
591591
});
592592

593-
it('devServer enabled only at the command line', function() {
593+
it('devServer enabled with https via configureDevServerOptions', function() {
594594
const config = createConfig();
595595
config.runtimeConfig.useDevServer = true;
596-
config.runtimeConfig.devServerHttps = true;
597596
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
598597
config.setPublicPath('/');
599598
config.addEntry('main', './main');
599+
config.configureDevServerOptions(options => {
600+
options.server = 'https';
601+
});
600602

601603
configGenerator(config);
602604
// this should be set when running the config generator

test/config/parse-runtime.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,6 @@ describe('parse-runtime', function() {
8080
expect(config.environment).to.equal('dev');
8181
expect(config.devServerHost).to.equal('foohost.l');
8282
expect(config.devServerPort).to.equal(9999);
83-
expect(config.devServerHttps).to.be.null;
84-
});
85-
86-
it('dev-server command https', function() {
87-
const testDir = createTestDirectory();
88-
const config = parseArgv(createArgv(['dev-server', '--https', '--host', 'foohost.l', '--port', '9999']), testDir);
89-
90-
expect(config.useDevServer).to.be.true;
91-
expect(config.devServerHost).to.equal('foohost.l');
92-
expect(config.devServerPort).to.equal(9999);
93-
expect(config.devServerHttps).to.equal(true);
9483
});
9584

9685
it('dev-server command server-type https', function() {
@@ -100,7 +89,6 @@ describe('parse-runtime', function() {
10089
expect(config.useDevServer).to.be.true;
10190
expect(config.devServerHost).to.equal('foohost.l');
10291
expect(config.devServerPort).to.equal(9999);
103-
expect(config.devServerHttps).to.equal(true);
10492
});
10593

10694
it('dev-server command public', function() {

test/config/path-util.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const expect = require('chai').expect;
1313
const WebpackConfig = require('../../lib/WebpackConfig');
1414
const RuntimeConfig = require('../../lib/config/RuntimeConfig');
1515
const pathUtil = require('../../lib/config/path-util');
16+
const configGenerator = require('../../lib/config-generator');
1617
const process = require('process');
1718

1819
function createConfig() {
@@ -166,4 +167,60 @@ describe('path-util getContentBase()', function() {
166167
expect(pathUtil.calculateDevServerUrl(runtimeConfig)).to.equal('https://myhost.local:9090');
167168
});
168169
});
170+
171+
describe('calculateDevServerUrl with configGenerator integration', function() {
172+
it('generates http URL without server option', function() {
173+
const config = createConfig();
174+
config.runtimeConfig.useDevServer = true;
175+
config.runtimeConfig.devServerHost = 'localhost';
176+
config.runtimeConfig.devServerPort = 8080;
177+
config.outputPath = '/tmp/public';
178+
config.setPublicPath('/');
179+
config.addEntry('main', './main');
180+
config.enableSingleRuntimeChunk();
181+
182+
// Run config generator to set devServerFinalIsHttps
183+
configGenerator(config);
184+
185+
expect(pathUtil.calculateDevServerUrl(config.runtimeConfig)).to.equal('http://localhost:8080');
186+
});
187+
188+
it('generates https URL with server: "https" option', function() {
189+
const config = createConfig();
190+
config.runtimeConfig.useDevServer = true;
191+
config.runtimeConfig.devServerHost = 'localhost';
192+
config.runtimeConfig.devServerPort = 8080;
193+
config.outputPath = '/tmp/public';
194+
config.setPublicPath('/');
195+
config.addEntry('main', './main');
196+
config.enableSingleRuntimeChunk();
197+
config.configureDevServerOptions(options => {
198+
options.server = 'https';
199+
});
200+
201+
// Run config generator to set devServerFinalIsHttps
202+
configGenerator(config);
203+
204+
expect(pathUtil.calculateDevServerUrl(config.runtimeConfig)).to.equal('https://localhost:8080');
205+
});
206+
207+
it('generates https URL with server: { type: "https" } option', function() {
208+
const config = createConfig();
209+
config.runtimeConfig.useDevServer = true;
210+
config.runtimeConfig.devServerHost = 'localhost';
211+
config.runtimeConfig.devServerPort = 8080;
212+
config.outputPath = '/tmp/public';
213+
config.setPublicPath('/');
214+
config.addEntry('main', './main');
215+
config.enableSingleRuntimeChunk();
216+
config.configureDevServerOptions(options => {
217+
options.server = { type: 'https' };
218+
});
219+
220+
// Run config generator to set devServerFinalIsHttps
221+
configGenerator(config);
222+
223+
expect(pathUtil.calculateDevServerUrl(config.runtimeConfig)).to.equal('https://localhost:8080');
224+
});
225+
});
169226
});

0 commit comments

Comments
 (0)