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

fix(remix-dev): update tailwind config detection to also look for cjs #5358

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fresh-toes-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/dev": patch
---

allow tailwind.config.cjs when using `future.unstable_tailwind`
16 changes: 11 additions & 5 deletions packages/remix-dev/compiler/utils/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { AcceptedPlugin, Processor } from "postcss";
import postcss from "postcss";

import type { RemixConfig } from "../../config";
import { findConfig } from "../../config";

interface Options {
config: RemixConfig;
Expand Down Expand Up @@ -119,13 +120,18 @@ async function loadTailwindPlugin(

try {
// First ensure they have a Tailwind config
require.resolve("./tailwind.config", { paths: [rootDirectory] });
// tailwind doesn't support esm config files yet
let tailwindConfigExtensions = [".js", ".cjs"];
let tailwindConfig = findConfig(
rootDirectory,
"tailwind.config",
tailwindConfigExtensions
);
if (!tailwindConfig) throw new Error("No Tailwind config found");

// Load Tailwind from the project directory
tailwindPath = require.resolve("tailwindcss", {
paths: [rootDirectory],
});
} catch (err) {
tailwindPath = require.resolve("tailwindcss", { paths: [rootDirectory] });
} catch {
// If they don't have a Tailwind config or Tailwind installed, just ignore it.
return null;
}
Expand Down
13 changes: 9 additions & 4 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export async function readConfig(
}

let rootDirectory = path.resolve(remixRoot);
let configFile = findConfig(rootDirectory, "remix.config");
let configFile = findConfig(rootDirectory, "remix.config", configExts);

let appConfig: AppConfig = {};
if (configFile) {
Expand Down Expand Up @@ -581,9 +581,14 @@ function findEntry(dir: string, basename: string): string | undefined {

const configExts = [".js", ".cjs", ".mjs"];

function findConfig(dir: string, basename: string): string | undefined {
for (let ext of configExts) {
let file = path.resolve(dir, basename + ext);
export function findConfig(
dir: string,
basename: string,
extensions: string[]
): string | undefined {
for (let ext of extensions) {
let name = basename + ext;
let file = path.join(dir, name);
if (fse.existsSync(file)) return file;
}

Expand Down