Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli-service): Support webpack5 devServer.server configuration #7024

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 9 additions & 4 deletions packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const defaults = {
host: '0.0.0.0',
port: 8080,
https: false
server: 'http'
}

/** @type {import('@vue/cli-service').ServicePlugin} */
Expand All @@ -24,7 +24,7 @@ module.exports = (api, options) => {
'--mode': `specify env mode (default: development)`,
'--host': `specify host (default: ${defaults.host})`,
'--port': `specify port (default: ${defaults.port})`,
'--https': `use https (default: ${defaults.https})`,
'--https': `use https (default: ${defaults.server === 'https' || defaults.server === 'spdy'})`,
'--public': `specify the public network URL for the HMR client`,
'--skip-plugins': `comma-separated list of plugin names to skip for this run`
}
Expand Down Expand Up @@ -98,8 +98,13 @@ module.exports = (api, options) => {
}
}

// Compatible with server in webpack5
const projectDevServerType = typeof projectDevServerOptions.server === 'string' ? projectDevServerOptions.server : typeof (projectDevServerOptions.server || {}).type === 'string' ? projectDevServerOptions.server.type : 'http'
const httpsTypes = ['https', 'spdy']
const serverSetting = args['server-type'] || (process.env.HTTPS === 'true' ? 'https' : 'http') || projectDevServerOptions.server || defaults.server

// resolve server options
const useHttps = args.https || projectDevServerOptions.https || defaults.https
const useHttps = args.https || args.http2 || process.env.HTTPS === 'true' || httpsTypes.includes(defaults.https) || httpsTypes.includes(args['server-type']) || httpsTypes.includes(projectDevServerType)
const protocol = useHttps ? 'https' : 'http'
const host = args.host || process.env.HOST || projectDevServerOptions.host || defaults.host
portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port
Expand Down Expand Up @@ -193,7 +198,7 @@ module.exports = (api, options) => {
}, projectDevServerOptions, {
host,
port,
https: useHttps,
server: serverSetting,
proxy: proxySettings,

static: {
Expand Down