This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* (BREAKING) Stops setting `host` / `public`, since they are only needed in a minority of use-cases (such as running inside a Docker container or having a proxy in front of webpack-dev-server), and the current implementation for them in `@neutrinojs/dev-server` is buggy. * (BREAKING) Stops supporting the `@neutrinojs/web` shorthand of setting `devServer.proxy` to a string, since it could only be used if the options it set were exactly what were required - which was often not the case given that proxy configuration is very project-specific. * Stops setting a `host` header on *responses* to the client, since it makes no sense (particularly it was set to the public host). It's possible that this was set thinking they would be set for *requests* to a proxy target, but that's not the case (and for that, `changeOrigin: true` would be more appropriate anyway). * Changes `output.publicPath` from `'./'` to `''` since the latter is equivalent (and is also the webpack default), however it correctly allows webpack-dev-server to fall back to `'/'` when needed: https://github.com/webpack/webpack-dev-server/blob/v3.1.9/lib/Server.js#L176 * Stops setting `devServer.publicPath` explicitly since it inherits from `output.publicPath` so should not normally need to be overridden: https://github.com/webpack/webpack-dev-server/blob/v3.1.9/bin/webpack-dev-server.js#L142-L152 * Stops setting `https: false`, since that's the default. Fixes #1169.
- Loading branch information
Showing
10 changed files
with
79 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,16 @@ | ||
const merge = require('deepmerge'); | ||
|
||
const isLocal = host => host === 'localhost' || host === '127.0.0.1'; | ||
const getHost = publicHost => (isLocal(publicHost) ? 'localhost' : '0.0.0.0'); | ||
const getPort = opts => opts.port || 5000; | ||
const getPublic = options => { | ||
const port = getPort(options); | ||
|
||
if (options.public) { | ||
const normalizedPath = options.public.split(':'); | ||
|
||
return normalizedPath.length === 2 | ||
? options.public | ||
: `${normalizedPath[0]}:${port}`; | ||
} | ||
|
||
return !options.host || isLocal(options.host) | ||
? `localhost:${port}` | ||
: `${options.host}:${port}`; | ||
}; | ||
|
||
module.exports = (neutrino, opts = {}) => { | ||
const port = getPort(opts); | ||
const publicHost = getPublic(opts); | ||
const host = getHost(publicHost); | ||
|
||
neutrino.config.devServer.merge(merge.all([ | ||
{ | ||
port, | ||
https: false, | ||
hot: true, | ||
historyApiFallback: true, | ||
publicPath: '/', | ||
headers: { | ||
host: publicHost | ||
}, | ||
// Only display compile duration and errors/warnings, to reduce noise when rebuilding. | ||
stats: { | ||
all: false, | ||
errors: true, | ||
timings: true, | ||
warnings: true | ||
} | ||
module.exports = (neutrino, options = {}) => { | ||
neutrino.config.devServer.merge({ | ||
port: 5000, | ||
hot: true, | ||
// Redirect 404s to index.html, so that apps that use the HTML 5 History API work. | ||
historyApiFallback: true, | ||
// Only display compile duration and errors/warnings, to reduce noise when rebuilding. | ||
stats: { | ||
all: false, | ||
errors: true, | ||
timings: true, | ||
warnings: true | ||
}, | ||
opts, | ||
{ host, public: publicHost } | ||
])); | ||
...options | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.