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

chore: upgrade dev middleware #2660

Merged
merged 26 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f192a40
chore(server): upgrade dev middleware and change options
knagaitsev Jun 25, 2020
cab2924
test(server): change noop invalidate test
knagaitsev Jun 26, 2020
78ebd08
chore(middleware): change how mime types work and use of middleware api
knagaitsev Jun 27, 2020
390da6c
chore(middleware): fix routes functionality with middleware
knagaitsev Jun 27, 2020
8aca25b
test(options): update create config test for public path
knagaitsev Jun 28, 2020
7489d41
test(options): update headers test
knagaitsev Jun 28, 2020
1d2dad9
refactor(server): remove stats option and use compiler stats option
knagaitsev Jun 29, 2020
bef4800
test(options): update options test and remove one error message
knagaitsev Jun 29, 2020
717bec4
test(server): update normalizeOptions test
knagaitsev Jun 29, 2020
b462d2d
test(server): update createConfig test
knagaitsev Jun 29, 2020
4d26b5d
test(server): update validation test and change tested option
knagaitsev Jun 29, 2020
6c927c7
test(server): update multi compiler test
knagaitsev Jun 29, 2020
22d97d5
test(cli): remove color cli test
knagaitsev Jun 29, 2020
99e31d9
chore(deps): remove supports color
knagaitsev Jun 29, 2020
3c0f598
test(server): update universal compiler test
knagaitsev Jun 29, 2020
948a4bc
chore(server): add headers option back and update tests
knagaitsev Jun 30, 2020
3f0f0b8
test(server): change title of header test
knagaitsev Jun 30, 2020
86f6b2a
test(server): update tests for headers option
knagaitsev Jun 30, 2020
121d999
chore(server): change devMiddleware name to dev
knagaitsev Jun 30, 2020
db4903e
chore(deps): upgrade webpack dev middleware for patch release
knagaitsev Jun 30, 2020
c8aec00
test(e2e): add delay between writing of css files and compilation
knagaitsev Jun 30, 2020
b657eb1
test(server): fix stats tests for webpack 5
knagaitsev Jun 30, 2020
157a26a
test(server): fix stats option test for webpack5
knagaitsev Jun 30, 2020
80a34c1
test(server): fix stats test value
knagaitsev Jun 30, 2020
3319b0b
fix(server): ignore stats objects that are empty
knagaitsev Jun 30, 2020
30b3443
test(server): fix test stability by adding unique port mappings
knagaitsev Jul 1, 2020
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
6 changes: 2 additions & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,9 @@ class Server {

setupDevMiddleware() {
// middleware for serving webpack bundle
this.middleware = webpackDevMiddleware(
this.middleware = webpackDevMiddleware.default(
this.compiler,
Object.assign({}, this.options, {
logger: this.logger,
})
this.options.devMiddleware
);
}

Expand Down
44 changes: 7 additions & 37 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@
}
]
},
"disableHostCheck": {
"type": "boolean"
},
"fs": {
"devMiddleware": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good place to do discussion, should we move all webpack-dev-middleware in the one place

/cc @hiroppy

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense because webpack-dev-middleware now does options validation that only allows for the properties specified. So we can just validate devMiddleware as an object, and if the user passes in bad webpack-dev-middleware options then webpack-dev-middleware validation will throw an error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename it to dev, I think it is unnecessary to have middleware suffix, we don't have it for other middlewares

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it will be better for CLI - webpack server --dev-something=value

"type": "object"
},
"headers": {
"type": "object"
"disableHostCheck": {
"type": "boolean"
},
"historyApiFallback": {
"anyOf": [
Expand Down Expand Up @@ -176,9 +173,6 @@
}
]
},
"index": {
"type": "string"
},
"injectClient": {
"anyOf": [
{
Expand All @@ -202,9 +196,6 @@
"liveReload": {
"type": "boolean"
},
"mimeTypes": {
"type": "object"
},
"onAfterSetupMiddleware": {
"instanceof": "Function"
},
Expand Down Expand Up @@ -302,18 +293,12 @@
"public": {
"type": "string"
},
"publicPath": {
"type": "string"
},
"requestCert": {
"type": "boolean"
},
"serveIndex": {
"type": "boolean"
},
"serverSideRender": {
"type": "boolean"
},
"socket": {
"type": "string"
},
Expand Down Expand Up @@ -374,16 +359,6 @@
},
"watchOptions": {
"type": "object"
},
"writeToDisk": {
"anyOf": [
{
"type": "boolean"
},
{
"instanceof": "Function"
}
]
}
},
"errorMessage": {
Expand All @@ -393,9 +368,8 @@
"client": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverclient)",
"compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)",
"contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)",
"devMiddleware": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverdevmiddleware-)",
"disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)",
"fs": "should be {Object} (https://github.com/webpack/webpack-dev-middleware#fs)",
"headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverheaders-)",
"historyApiFallback": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback)",
"host": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserverhost)",
"hot": "should be {Boolean|String} (https://webpack.js.org/configuration/dev-server/#devserverhot)",
Expand All @@ -404,8 +378,7 @@
"index": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverindex)",
"injectClient": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverinjectclient)",
"injectHot": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverinjecthot)",
"liveReload": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlivereload-)",
"mimeTypes": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devservermimetypes-)",
"liveReload": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverlivereload)",
"onAfterSetupMiddleware": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserverafter)",
"onBeforeSetupMiddleware": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserverbefore)",
"onListening": "should be {Function} (https://webpack.js.org/configuration/dev-server/#onlistening)",
Expand All @@ -417,19 +390,16 @@
"progress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverprogress---cli-only)",
"proxy": "should be {Object|Array} (https://webpack.js.org/configuration/dev-server/#devserverproxy)",
"public": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublic)",
"publicPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverpublicpath-)",
"requestCert": "should be {Boolean}",
"contentBasePublicPath": "should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbasepublicpath)",
"serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)",
"serverSideRender": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#serversiderender)",
"socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversocket)",
"staticOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverstaticoptions)",
"stats": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverstats-)",
"stats": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverstats)",
"transportMode": "should be {String|Object} (https://webpack.js.org/configuration/dev-server/#devservertransportmode)",
"useLocalIp": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserveruselocalip)",
"watchContentBase": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverwatchcontentbase)",
"watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverwatchoptions-)",
"writeToDisk": "should be {Boolean|Function} (https://webpack.js.org/configuration/dev-server/#devserverwritetodisk-)"
"watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverwatchoptions)"
}
},
"additionalProperties": false
Expand Down
12 changes: 7 additions & 5 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ function createConfig(config, argv, { port }) {
options.overlay = argv.overlay;
}

if (!options.publicPath) {
options.devMiddleware = options.devMiddleware || {};

if (!options.devMiddleware.publicPath) {
// eslint-disable-next-line
options.publicPath =
options.devMiddleware.publicPath =
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is really bad idea smile But let's resolve it on the other PR


if (
!isAbsoluteUrl(String(options.publicPath)) &&
options.publicPath[0] !== '/'
!isAbsoluteUrl(String(options.devMiddleware.publicPath)) &&
options.devMiddleware.publicPath[0] !== '/'
) {
options.publicPath = `/${options.publicPath}`;
options.devMiddleware.publicPath = `/${options.devMiddleware.publicPath}`;
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/utils/normalizeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function normalizeOptions(compiler, options) {
options.client.path = `/${
options.client.path ? options.client.path.replace(/^\/|\/$/g, '') : 'ws'
}`;

options.devMiddleware = options.devMiddleware || {};
}

module.exports = normalizeOptions;
60 changes: 31 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"supports-color": "^7.1.0",
"url": "^0.11.0",
"util": "^0.12.3",
"webpack-dev-middleware": "^3.7.2",
"webpack-dev-middleware": "^4.0.0-rc.1",
"ws": "^7.2.5",
"yargs": "^13.3.2"
},
Expand Down