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

Configuration file content relative paths are not relative to the configuration file location #13517

Closed
qdm12 opened this issue Apr 12, 2024 · 2 comments

Comments

@qdm12
Copy link

qdm12 commented Apr 12, 2024

What version of Tailwind CSS are you using? v3.4.3

What build tool (or framework if it abstracts the build tool) are you using? using standalone tailwindcss binary.

What version of Node.js are you using? N/A

What browser are you using? Irrelevant

What operating system are you using? Alpine Linux x86_64

Reproduction URL Dockerfile to re-produce the environment and error:

  1. Copy the following to a Dockerfile file

    FROM alpine:3.19
    RUN wget -qO /usr/local/bin/tailwindcss https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.3/tailwindcss-linux-x64 && \
      chmod +x /usr/local/bin/tailwindcss
    WORKDIR /workdir
    # Create an input.css with an import to the base components
    RUN echo '@tailwind utilities;' > input.css
    # Create a tailwind.config.js file with *.html as its content
    RUN printf "/** @type {import('tailwindcss').Config} */\nmodule.exports = {\ncontent: [\"*.html\"]\n}\n" > tailwind.config.js
    # Create a simple HTML file using a Tailwind class
    RUN echo '<div class="text-2xl">Test</div>' > index.html
    
    # FAILURE: try to generate an output.css file from a directory where the tailwind config is NOT located.
    # /workdir/index.html is NOT detected and output.css is empty.
    WORKDIR /workdir/subdirectory
    RUN tailwindcss -c /workdir/tailwind.config.js -i /workdir/input.css -o /workdir/output.css
    RUN cat /workdir/output.css
    # Empty line
    
    # SUCCESS: generate an output.css file from the directory where the tailwind config is located.
    WORKDIR /workdir
    RUN tailwindcss -c /workdir/tailwind.config.js -i /workdir/input.css -o /workdir/output.css
    RUN cat /workdir/output.css
    # .text-2xl {
    #   font-size: 1.5rem;
    #   line-height: 2rem
    # }
  2. Build it with docker build . and check results from RUN cat /workdir/output.css instructions

Describe your issue: Relative paths in the content array of the configuration file tailwind.config.js are relative to your CURRENT PATH and not to where the configuration file tailwind.config.js is located. The change needed is to make relative paths from the configuration file to be relative to the configuration file and NOT from the current path where tailwindcss is invoked. Note the --content flag should stay as it is, and have relative paths relative to the current directory, so be careful not to break this behavior.

For a more detailed context, I need this fixed in order to call tailwindcss from subdirectories, from Go //go:generate tailwindcss ... commands.

Thanks!

@adamwathan
Copy link
Member

Hey! See the relevant documentation here: https://tailwindcss.com/docs/content-configuration#using-relative-paths

@qdm12
Copy link
Author

qdm12 commented Apr 12, 2024

Awesome, thank you, and my apologies I didn't see that piece of documentation. 💯

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

No branches or pull requests

2 participants