Skip to content

Commit 8ea2b58

Browse files
authored
refactor: bundle connect-history-api-fallback (#181)
1 parent af0a8d5 commit 8ea2b58

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"@rspack/dev-middleware": "^2.0.0",
4949
"@types/ws": "^8.18.1",
5050
"chokidar": "^5.0.0",
51-
"connect-history-api-fallback": "^2.0.0",
5251
"connect-next": "^4.0.0",
5352
"ws": "^8.20.0"
5453
},
@@ -59,11 +58,13 @@
5958
"@rspack/core": "2.0.0-rc.0",
6059
"@rspack/plugin-react-refresh": "1.6.1",
6160
"@rstest/core": "^0.9.5",
61+
"@types/connect-history-api-fallback": "^1.5.4",
6262
"@types/mime-types": "3.0.1",
6363
"@types/node": "^24.12.0",
6464
"@types/serve-static": "^2.2.0",
6565
"@types/trusted-types": "^2.0.7",
6666
"@types/ws": "8.18.1",
67+
"connect-history-api-fallback": "^2.0.0",
6768
"cross-env": "^10.1.0",
6869
"css-loader": "^7.1.4",
6970
"express": "^5.2.1",

pnpm-lock.yaml

Lines changed: 41 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rslib.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export default defineConfig({
88
dts: true,
99
output: {
1010
externals: {
11-
'connect-history-api-fallback':
12-
'commonjs connect-history-api-fallback',
1311
selfsigned: 'commonjs selfsigned',
1412
},
1513
},

src/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,9 @@ class Server<
18651865
}
18661866

18671867
if (this.options.historyApiFallback) {
1868-
const connectHistoryApiFallback = require('connect-history-api-fallback');
1868+
const { default: connectHistoryApiFallback } = await import(
1869+
/* webpackChunkName: "connect-history-api-fallback" */ 'connect-history-api-fallback'
1870+
);
18691871

18701872
const { historyApiFallback } = this.options;
18711873

@@ -1885,7 +1887,7 @@ class Server<
18851887
name: 'connect-history-api-fallback',
18861888
middleware: connectHistoryApiFallback(
18871889
historyApiFallback as ConnectHistoryApiFallbackOptions,
1888-
),
1890+
) as DevServerMiddlewareHandler,
18891891
});
18901892

18911893
// include our middleware to ensure

0 commit comments

Comments
 (0)