Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/config/RuntimeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lib/config/parse-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
25 changes: 25 additions & 0 deletions test/bin/encore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -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();
});

Expand Down
1 change: 1 addition & 0 deletions test/config/parse-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Loading