Loosie94
Loosie94

Reputation: 665

Tailwind presets get dynamic filename from .env file

I'm tying go get Tailwind to work with multiple configurations. As I read in the docs, I could use presets for this.

Now I've created a second file called: "tailwind.clientname.js", and then called it within the tailwind.config.js file. Like so:

const project = process.env.PROJECT

module.exports = {
    presets: [require('./tailwind.' + project + '.js')],
}

I also created a .env file with the content:

PROJECT="clientname"

But when I run my yarn watch script, Tailwind doesn't seem to see the .env value It returns as tailwind.undefined.js.

How can I make this work? Do I miss a dependency? Thanks!

Upvotes: 1

Views: 1312

Answers (1)

Ihar Aliakseyenka
Ihar Aliakseyenka

Reputation: 14233

By default process.env (object containing the user environment) has no access to variables from .env file. To be able to load these variables from .env file you may install dotenv package

Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env

Upvotes: 1

Related Questions