Follow-up #1400 (fix URLs generation)

Looks like I went a bit too far, the URLs generated in `entrypoints.json` and `manifest.json` were always in `http://` even when using flag `--server-type https`
This commit is contained in:
Hugo Alliaume
2026-03-12 09:05:20 +01:00
parent 5557f89d73
commit 3e149b93fa
5 changed files with 40 additions and 0 deletions

View File

@@ -604,6 +604,7 @@ class ConfigGenerator {
headers: { 'Access-Control-Allow-Origin': '*' },
compress: true,
historyApiFallback: true,
// disabled to let HMR handle updates without full page reloads
liveReload: false,
// see https://github.com/symfony/webpack-encore/issues/931#issuecomment-784483725
host: this.webpackConfig.runtimeConfig.devServerHost,
@@ -613,6 +614,14 @@ class ConfigGenerator {
port: this.webpackConfig.runtimeConfig.devServerPort,
};
// Forward the --server-type CLI flag (e.g. --server-type https) so
// that devServerFinalIsHttps can be determined in getWebpackConfig().
// configureDevServerOptions() takes precedence if it sets "server".
// Use object form { type: ... } so webpack-cli can merge --server-type on top.
if (this.webpackConfig.runtimeConfig.devServerServerType) {
devServerOptions.server = { type: this.webpackConfig.runtimeConfig.devServerServerType };
}
return applyOptionsCallback(
this.webpackConfig.devServerOptionsConfigurationCallback,
devServerOptions

View File

@@ -17,6 +17,7 @@ class RuntimeConfig {
this.environment = process.env.NODE_ENV ? process.env.NODE_ENV : 'dev';
this.useDevServer = false;
this.devServerServerType = null;
// see config-generator - getWebpackConfig()
this.devServerFinalIsHttps = null;
this.devServerHost = null;

View File

@@ -50,6 +50,10 @@ module.exports = function(argv, cwd) {
runtimeConfig.devServerHost = argv.host ? argv.host : 'localhost';
runtimeConfig.devServerPort = argv.port ? argv.port : '8080';
if (argv.serverType) {
runtimeConfig.devServerServerType = argv.serverType;
}
break;
}

View File

@@ -276,6 +276,18 @@ module.exports = Encore.getWebpackConfig();
expect(stderr).to.contain('[webpack-dev-server] Loopback: http://localhost:8080/');
expect(stderr).to.contain('[webpack-dev-server] Content not from webpack is served from');
// Verify entrypoints.json contains http:// URLs
const entrypoints = JSON.parse(
fs.readFileSync(path.join(testDir, 'build', 'entrypoints.json'), 'utf8')
);
expect(entrypoints.entrypoints.main.js[0]).to.contain('http://localhost:8080/build/');
// Verify manifest.json contains http:// URLs
const manifest = JSON.parse(
fs.readFileSync(path.join(testDir, 'build', 'manifest.json'), 'utf8')
);
expect(manifest['build/main.js']).to.contain('http://localhost:8080/build/');
done();
});
@@ -344,6 +356,19 @@ module.exports = Encore.getWebpackConfig();
expect(stderr).to.contain('[webpack-dev-server] Loopback: https://localhost:8080/');
expect(stderr).to.contain('[webpack-dev-server] Content not from webpack is served from');
// Verify entrypoints.json contains https:// URLs
const entrypoints = JSON.parse(
fs.readFileSync(path.join(testDir, 'build', 'entrypoints.json'), 'utf8')
);
expect(entrypoints.entrypoints.main.js[0]).to.contain('https://localhost:8080/build/');
// Verify manifest.json contains https:// URLs
const manifest = JSON.parse(
fs.readFileSync(path.join(testDir, 'build', 'manifest.json'), 'utf8')
);
expect(manifest['build/main.js']).to.contain('https://localhost:8080/build/');
done();
});

View File

@@ -87,6 +87,7 @@ describe('parse-runtime', function() {
const config = parseArgv(createArgv(['dev-server', '--server-type', 'https', '--host', 'foohost.l', '--port', '9999']), testDir);
expect(config.useDevServer).to.be.true;
expect(config.devServerServerType).to.equal('https');
expect(config.devServerHost).to.equal('foohost.l');
expect(config.devServerPort).to.equal(9999);
});