Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 32c3d90

Browse files
committedJun 3, 2021
feat: add new option
1 parent 51054a9 commit 32c3d90

10 files changed

+1876
-3627
lines changed
 

‎CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [5.0.0](https://github.com/webpack/webpack-dev-middleware/compare/v4.3.0...v5.0.0) (2021-06-02)
6+
7+
8+
### ⚠ BREAKING CHANGES
9+
10+
* minimum supported `Node.js` version is `12.13.0` ([#928](https://github.com/webpack/webpack-dev-middleware/issues/928)) ([4cffeff](https://github.com/webpack/webpack-dev-middleware/commit/4cffeffb5fd07ea79e5a7a5a0cdb3f08f3856c06))
11+
512
## [4.3.0](https://github.com/webpack/webpack-dev-middleware/compare/v4.2.0...v4.3.0) (2021-05-19)
613

714

‎README.md

+7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ The public path that the middleware is bound to.
124124

125125
_Best Practice: use the same `publicPath` defined in your webpack config. For more information about `publicPath`, please see [the webpack documentation](https://webpack.js.org/guides/public-path)._
126126

127+
### historyApiFallback
128+
129+
type: `Boolean`
130+
Default: `false`
131+
132+
When using the HTML5 History API, the index.html page will likely have to be served in place of any 404 responses. Enable historyApiFallback by setting it to true
133+
127134
### stats
128135

129136
Type: `Boolean|String|Object`

‎babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (api) => {
1010
"@babel/preset-env",
1111
{
1212
targets: {
13-
node: "10.13.0",
13+
node: "12.13.0",
1414
},
1515
},
1616
],

‎package-lock.json

+1,811-3,611
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-dev-middleware",
3-
"version": "4.3.0",
3+
"version": "5.0.0",
44
"description": "A development middleware for webpack",
55
"license": "MIT",
66
"repository": "webpack/webpack-dev-middleware",
@@ -13,16 +13,16 @@
1313
"url": "https://opencollective.com/webpack"
1414
},
1515
"engines": {
16-
"node": ">= v10.23.3"
16+
"node": ">= 12.13.0"
1717
},
1818
"scripts": {
1919
"commitlint": "commitlint --from=master",
20-
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
20+
"fmt:check": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
2121
"lint:js": "eslint --cache src test",
22-
"lint": "npm-run-all -l -p \"lint:**\"",
23-
"fix:prettier": "npm run lint:prettier -- --write",
22+
"lint": "npm-run-all lint:js fmt:check",
23+
"fmt": "npm run fmt:check -- --write",
2424
"fix:js": "npm run lint:js -- --fix",
25-
"fix": "npm-run-all fix:js fix:prettier",
25+
"fix": "npm-run-all fix:js fmt",
2626
"prepare": "husky install && npm run build",
2727
"build": "del dist && babel src -d dist --copy-files",
2828
"release": "standard-version",
@@ -43,18 +43,18 @@
4343
"colorette": "^1.2.2",
4444
"mem": "^8.1.1",
4545
"memfs": "^3.2.2",
46-
"mime-types": "^2.1.30",
46+
"mime-types": "^2.1.31",
4747
"range-parser": "^1.2.1",
4848
"schema-utils": "^3.0.0"
4949
},
5050
"devDependencies": {
5151
"@babel/cli": "^7.14.3",
5252
"@babel/core": "^7.14.3",
53-
"@babel/preset-env": "^7.14.2",
53+
"@babel/preset-env": "^7.14.4",
5454
"@commitlint/cli": "^12.1.4",
5555
"@commitlint/config-conventional": "^12.1.4",
5656
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
57-
"babel-jest": "^26.6.3",
57+
"babel-jest": "^27.0.2",
5858
"chokidar": "^3.5.1",
5959
"connect": "^3.7.0",
6060
"cross-env": "^7.0.3",
@@ -63,19 +63,19 @@
6363
"del-cli": "^3.0.1",
6464
"eslint": "^7.26.0",
6565
"eslint-config-prettier": "^8.3.0",
66-
"eslint-plugin-import": "^2.22.1",
67-
"execa": "^5.0.0",
66+
"eslint-plugin-import": "^2.23.4",
67+
"execa": "^5.0.1",
6868
"express": "^4.17.1",
6969
"file-loader": "^6.2.0",
7070
"husky": "^6.0.0",
71-
"jest": "^26.6.3",
71+
"jest": "^27.0.3",
7272
"lint-staged": "^11.0.0",
7373
"npm-run-all": "^4.1.5",
7474
"prettier": "^2.3.0",
7575
"standard-version": "^9.3.0",
7676
"strip-ansi": "^6.0.0",
7777
"supertest": "^6.1.3",
78-
"webpack": "^5.37.0"
78+
"webpack": "^5.38.1"
7979
},
8080
"keywords": [
8181
"webpack",

‎src/options.json

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
}
4949
]
5050
},
51+
"historyApiFallback": {
52+
"description": "When using the HTML5 History API, the index.html page will likely have to be served in place of any 404 responses. Enable historyApiFallback by setting it to true",
53+
"type": "boolean"
54+
},
5155
"stats": {
5256
"description": "Stats options object or preset name.",
5357
"anyOf": [

‎src/utils/getFilenameFromUrl.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ export default function getFilenameFromUrl(context, url) {
5353
filename = path.join(outputPath, querystring.unescape(pathname));
5454
}
5555

56-
let fsStats;
56+
if (
57+
!context.outputFileSystem.existsSync(filename) &&
58+
options.historyApiFallback
59+
) {
60+
filename = path.join(outputPath);
61+
}
5762

63+
let fsStats;
5864
try {
5965
fsStats = context.outputFileSystem.statSync(filename);
6066
} catch (_ignoreError) {

‎test/logging.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ describe("logging", () => {
851851
});
852852

853853
if (os.platform() !== "win32") {
854-
it('should logging an error from the fs error when the "writeToDisk" option is "true"', async (done) => {
854+
it('should logging an error from the fs error when the "writeToDisk" option is "true"', (done) => {
855855
// eslint-disable-next-line global-require
856856
const clearDirectory = require("./helpers/clearDirectory").default;
857857
const outputDir = path.resolve(

‎test/middleware.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,27 @@ describe.each([
25662566
});
25672567
});
25682568

2569+
describe("historyApiFallback option", () => {
2570+
describe("index.html page will likely have to be served in place of any 404 responses", () => {
2571+
beforeAll((done) => {
2572+
const compiler = getCompiler(webpackConfig);
2573+
2574+
instance = middleware(compiler, { historyApiFallback: true });
2575+
2576+
app = framework();
2577+
app.use(instance);
2578+
2579+
listen = listenShorthand(done);
2580+
});
2581+
2582+
afterAll(close);
2583+
2584+
it('should return the "200" code for the "GET" request', (done) => {
2585+
request(app).get("/foo/bar/baz").expect(200, done);
2586+
});
2587+
});
2588+
});
2589+
25692590
describe("serverSideRender option", () => {
25702591
let locals;
25712592

‎test/validation-options.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ describe("validation", () => {
3535
success: ["/foo", "", "auto", () => "/public/path"],
3636
failure: [false],
3737
},
38+
historyApiFallback: {
39+
success: [true],
40+
failure: [],
41+
},
3842
serverSideRender: {
3943
success: [true],
4044
failure: ["foo", 0],

0 commit comments

Comments
 (0)
Please sign in to comment.