mirror of
https://github.com/symfony/webpack-encore.git
synced 2026-03-24 00:12:07 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user