Skip to content

Commit

Permalink
fix: escape vite asset import suffixes (#46)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
barakcodes and yusukebe authored Dec 6, 2024
1 parent 6963bfb commit 3e1ee79
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/cloudflare-pages/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LoaderFunctionArgs } from '@remix-run/cloudflare'
import { useLoaderData } from '@remix-run/react'
import logoDark from '/logo-dark.png?inline'

export const loader = (args: LoaderFunctionArgs) => {
const extra = args.context.extra
Expand All @@ -23,6 +24,7 @@ export default function Index() {
<h4>Extra is {extra}</h4>
<h5>Var in Variables is {myVarInVariables}</h5>
<h6>waitUntil is {isWaitUntilDefined ? 'defined' : 'not defined'}</h6>
<img src={logoDark} alt='Remix' />
</div>
)
}
3 changes: 3 additions & 0 deletions examples/cloudflare-pages/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ test('Should return 200 response - /', async ({ page }) => {

const contentH6 = await page.textContent('h6')
expect(contentH6).toBe('waitUntil is defined')

const imageResponse = await page.goto('/logo-dark.png?inline')
expect(imageResponse?.status()).toBe(200)
})

test('Should return 200 response - /api', async ({ page }) => {
Expand Down
Binary file added examples/cloudflare-pages/public/favicon.ico
Binary file not shown.
Binary file added examples/cloudflare-pages/public/logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default (options: Options): Plugin => {
'/assets/**',
'/app/**',
'/src/app/**',
// matches for vite's import assets suffixes
/\?(import(&)?)?(inline|url|no-inline|raw)?$/,
],
injectClientScript: false,
loadModule: async (server, entry) => {
Expand Down

0 comments on commit 3e1ee79

Please sign in to comment.