Skip to content

Commit

Permalink
fix(router-plugin): plugin functionality for rspack 1.x.x (#2153)
Browse files Browse the repository at this point in the history
* fix(router-plugin): bump dependencies to latest

* chore(router-plugin): remove vite from the dev dependencies

* chore: bump rspack deps for "quickstart-rspack-file-based" to 1.0-level deps

* chore(router-plugin): bump rspack peerDep level to 1.0.0

* types(router-plugin): explicit casting of ResolveData

* refactor(router-plugin): `transform` in the code-splitter no longer needs to be async
  • Loading branch information
SeanCassiere authored Aug 20, 2024
1 parent 4d787a8 commit de2325b
Show file tree
Hide file tree
Showing 4 changed files with 528 additions and 125 deletions.
4 changes: 2 additions & 2 deletions examples/react/quickstart-rspack-file-based/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@rsbuild/core": "^0.7.10",
"@rsbuild/plugin-react": "^0.7.10",
"@rsbuild/core": "1.0.1-beta.15",
"@rsbuild/plugin-react": "1.0.1-beta.15",
"@tanstack/router-plugin": "^1.48.3",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
Expand Down
13 changes: 5 additions & 8 deletions packages/router-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,19 @@
"@types/babel__traverse": "^7.20.6",
"babel-dead-code-elimination": "^1.0.6",
"chokidar": "^3.6.0",
"unplugin": "^1.11.0",
"unplugin": "^1.12.2",
"zod": "^3.23.8"
},
"devDependencies": {
"vite": "^5.3.5"
},
"peerDependencies": {
"@rsbuild/core": ">=0.7.9",
"vite": ">=5.0.13",
"@rsbuild/core": ">=1.0.0",
"vite": ">=5.0.0",
"webpack": ">=5.92.0"
},
"peerDependenciesMeta": {
"vite": {
"@rsbuild/core": {
"optional": true
},
"@rsbuild/core": {
"vite": {
"optional": true
},
"webpack": {
Expand Down
10 changes: 5 additions & 5 deletions packages/router-plugin/src/code-splitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
return null
},

async transform(code, id) {
transform(code, id) {
if (!userConfig.experimental?.enableCodeSplitting) {
return null
}
Expand All @@ -127,7 +127,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
id = fileURLToPath(url).replace(/\\/g, '/')

if (id.includes(splitPrefix)) {
return await handleSplittingFile(code, id)
return handleSplittingFile(code, id)
} else if (
fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&
(code.includes('createRoute(') || code.includes('createFileRoute('))
Expand All @@ -142,7 +142,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
}
}

return await handleCompilingFile(code, id)
return handleCompilingFile(code, id)
}

return null
Expand Down Expand Up @@ -181,7 +181,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {
self.normalModuleFactory.hooks.beforeResolve.tap(
PLUGIN_NAME,
(resolveData) => {
(resolveData: { request: string }) => {
if (resolveData.request.includes(JoinedSplitPrefix)) {
resolveData.request = resolveData.request.replace(
JoinedSplitPrefix,
Expand All @@ -201,7 +201,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {
self.normalModuleFactory.hooks.beforeResolve.tap(
PLUGIN_NAME,
(resolveData) => {
(resolveData: { request: string }) => {
if (resolveData.request.includes(JoinedSplitPrefix)) {
resolveData.request = resolveData.request.replace(
JoinedSplitPrefix,
Expand Down
Loading

0 comments on commit de2325b

Please sign in to comment.