forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(remix-dev/vite): tree-shake unused route exports (remix-run#8468)
- Loading branch information
1 parent
69ab6ac
commit ee1f202
Showing
3 changed files
with
99 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@remix-run/dev": patch | ||
--- | ||
|
||
Vite: Tree-shake unused route exports in the client build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as path from "node:path"; | ||
import { test, expect } from "@playwright/test"; | ||
|
||
import { createProject, grep, viteBuild } from "./helpers/vite.js"; | ||
|
||
test("Vite / dead-code elimination for unused route exports", async () => { | ||
let cwd = await createProject({ | ||
"app/routes/custom-route-exports.tsx": String.raw` | ||
const unusedMessage = "ROUTE_EXPORT_THAT_ISNT_USED"; | ||
const usedMessage = "ROUTE_EXPORT_THAT_IS_USED"; | ||
export const unusedRouteExport = unusedMessage; | ||
export const usedRouteExport = usedMessage; | ||
export default function CustomExportsRoute() { | ||
return <h1>Custom route exports</h1> | ||
} | ||
`, | ||
"app/routes/use-route-export.tsx": String.raw` | ||
import { usedRouteExport } from "./custom-route-exports"; | ||
export default function CustomExportsRoute() { | ||
return <h1>{usedRouteExport}</h1> | ||
} | ||
`, | ||
}); | ||
let { status } = viteBuild({ cwd }); | ||
expect(status).toBe(0); | ||
|
||
expect( | ||
grep(path.join(cwd, "build/client"), /ROUTE_EXPORT_THAT_ISNT_USED/).length | ||
).toBe(0); | ||
|
||
expect( | ||
grep(path.join(cwd, "build/client"), /ROUTE_EXPORT_THAT_IS_USED/).length | ||
).toBeGreaterThanOrEqual(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters