Skip to content

Commit 3e1ee79

Browse files
barakcodesyusukebe
andauthored
fix: escape vite asset import suffixes (#46)
* fix: escape vite asset import suffixes Add the regix to exclude all vite asset import suffixes, might be better done in the @hono/vite-dev-server, but this fixes the issue for now * move the image and add a test for vite dev --------- Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
1 parent 6963bfb commit 3e1ee79

File tree

5 files changed

+7
-0
lines changed

5 files changed

+7
-0
lines changed

examples/cloudflare-pages/app/routes/_index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LoaderFunctionArgs } from '@remix-run/cloudflare'
22
import { useLoaderData } from '@remix-run/react'
3+
import logoDark from '/logo-dark.png?inline'
34

45
export const loader = (args: LoaderFunctionArgs) => {
56
const extra = args.context.extra
@@ -23,6 +24,7 @@ export default function Index() {
2324
<h4>Extra is {extra}</h4>
2425
<h5>Var in Variables is {myVarInVariables}</h5>
2526
<h6>waitUntil is {isWaitUntilDefined ? 'defined' : 'not defined'}</h6>
27+
<img src={logoDark} alt='Remix' />
2628
</div>
2729
)
2830
}

examples/cloudflare-pages/e2e.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ test('Should return 200 response - /', async ({ page }) => {
2424

2525
const contentH6 = await page.textContent('h6')
2626
expect(contentH6).toBe('waitUntil is defined')
27+
28+
const imageResponse = await page.goto('/logo-dark.png?inline')
29+
expect(imageResponse?.status()).toBe(200)
2730
})
2831

2932
test('Should return 200 response - /api', async ({ page }) => {
16.6 KB
Binary file not shown.
78.4 KB
Loading

src/vite-plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default (options: Options): Plugin => {
3131
'/assets/**',
3232
'/app/**',
3333
'/src/app/**',
34+
// matches for vite's import assets suffixes
35+
/\?(import(&)?)?(inline|url|no-inline|raw)?$/,
3436
],
3537
injectClientScript: false,
3638
loadModule: async (server, entry) => {

0 commit comments

Comments
 (0)