webpack-dev-middleware
webpack-dev-middleware copied to clipboard
Allow setting default mime-type from webpack config.
Feature Proposal
Configuration option to set default mime-type
// webpack.dev.js
module.exports = {
devServer: {
devMiddleWare: {
// provide default when mime-type evals to false.
mimeTypeDefault: 'text/html'
}
}
}
Stack overflow issue detailing the context in which this use case arose: https://stackoverflow.com/questions/70011373/how-to-configure-webpack-dev-server-to-serve-extensionless-files-as-text-html
Feature Use Case
For developing applications with pages that don't have a file extension. E.g. localhost:8080/example. It would be convenient to be able to specify a default mime-type for files that don't have a file extension; specifically, 'text/html'.
Current State
The express server will emit this content type as application/octet-stream
even though middleware goes out of it's way to avoid inappropriately setting a mime-type at middleware.js#L104-L113. Express uses mime 1.6 which eventually fills in a default type at mine.js#L69-L73 The result being there is a default content type, and it's determined further down in the stack.
In production deployment this is not a problem. Configuring production web servers to emit the desired mime type, re-writing the requests, or specifying the mime-type in metadata makes this not a production issue.
Please paste the results of npx webpack-cli info
here, and mention other relevant information
∫ wp5-extensionless/webpack-boilerplate (main)⮞ npx webpack-cli info
System:
OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
Memory: 11.16 GB / 31.31 GB
Binaries:
Node: 16.13.0 - /usr/bin/node
npm: 8.1.0 - /usr/bin/npm
Browsers:
Firefox: 94.0
Packages:
babel-loader: ^8.2.2 => 8.2.2
clean-webpack-plugin: ^4.0.0 => 4.0.0
copy-webpack-plugin: ^9.0.1 => 9.0.1
css-loader: ^6.4.0 => 6.4.0
css-minimizer-webpack-plugin: ^3.1.1 => 3.1.1
eslint-import-resolver-webpack: ^0.13.1 => 0.13.1
html-webpack-plugin: ^5.3.2 => 5.3.2
postcss-loader: ^6.2.0 => 6.2.0
sass-loader: ^12.2.0 => 12.2.0
style-loader: ^3.3.0 => 3.3.0
webpack: ^5.58.2 => 5.58.2
webpack-cli: ^4.9.0 => 4.9.0
webpack-dev-server: ^4.3.1 => 4.3.1
webpack-merge: ^5.8.0 => 5.8.0
PR welcome