Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fastify-htmx): allow for imports without file extensions #200

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

janmonschke
Copy link

I noticed that some client imports where not properly included in vite's output. This was the setup:

data.tsx

import { ListItem } from "../components/ListItem"

export default async function ({ app, req, reply }) {
  return (...)
}

../components/ListItem.tsx

import type { PropsWithChildren } from "@kitajs/html";
import styles from "./ListItem.module.css";

export function ListItem({ children }: PropsWithChildren) {
  return (
    <li class={styles.ListItem} safe>
      {children}
    </li>
  );
}

./ListItem.module.css

.ListItem {
  color: red;
}

I expected the list items to be red but they were not. Upon further investigation, I noticed that the CSS code from ListItem.module.css was generated but not included in the output.

The problem stemmed from this line in data.tsx:

import { ListItem } from "../components/ListItem"

The import does not include the file extension but the checks in findClientImports rely on the file extension to be present:

return specifier.match(/\.((svg)|(css)|(m?js)|(tsx?)|(jsx?))$/)

In this PR I'm adding a step to resolve the file extension in case it's not defined. This allows for imports without file extensions to be correctly resolved and included in the bundle.

Copy link

netlify bot commented Feb 21, 2025

Deploy Preview for agitated-mahavira-26f8f9 canceled.

Name Link
🔨 Latest commit 07461e2
🔍 Latest deploy log https://app.netlify.com/sites/agitated-mahavira-26f8f9/deploys/67b8e3b28174100008e52581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant