[RFC] Configure Tailwind CSS more intuitively #4509
chenjiahan
started this conversation in
RFC Discussions
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
There are currently some issues with the use of Tailwind CSS in Modern.js.
This RFC will discuss these issues and provide a usage approach that is more in line with community conventions.
Background
Currently, Modern.js provides two options to configure Tailwind CSS:
theme
option of Tailwind CSS.theme
option.Tailwind CSS officially uses the
tailwind.config.{js,ts,cjs,mjs}
file, which is not supported by the current version of Modern.js.There are several problems with the current implementation:
theme
option totools.tailwindcss
, the@modern-js/plugin-tailwindcss
will throw an error, because the users are expected to usesource.designSystem
:Motivation
In this RFC, we want to solve the current problems and make it more intuitive to configure Tailwind CSS in Modern.js.
The most natural way is to configure
tailwind.config.js
directly, and Modern.js will read the config automatically, so that users do not need to configure thetools.tailwindcss
orsource.designSystem
. And the Tailwind CSS autocomplete will work out-of-box.Detailed Design
Read Tailwind CSS config file
The
@modern-js/plugin-tailwindcss
will usetailwindcss/loadConfig
to read the following config files if they exist:The config object will be used to configure the PostCSS plugin of Tailwind CSS.
It is no longer recommended to use
tools.tailwindcss
orsource.designSystem
. But iftools.tailwindcss
andtailwind.config.*
are used at the same time, they will be merged viaObject.assign
and the priority will be as follows:source.designSystem
will overridetools.tailwindcss.theme
.tools.tailwindcss
will overridetailwind.config.*
.Allow use of
tools.tailwindcss.theme
It is now allowed to use
tools.tailwindcss.theme
, which means thattools.tailwindcss
is exactly the same as the native Tailwind CSS config.Auto create
tailwind.config.ts
The
tailwind.config.ts
file will be created automatically after running themodern new
command, and it will contain some default configs:Invalidate the webpack cache
When the
tailwind.config.*
file is updated, it should invalidate the webpack cache, so we need to addtailwind.config.*
towebpack.cache.buildDependencies
to ensure this.Deprecating
source.designSystem
The
source.designSystem
config will be deprecated, it can still work in Modern.js 2.x, but we will recommend the new methods:tailwind.config.*
for Tailwind CSS users.designSystem
with Styled Components.The
tools.tailwindcss
config will not be deprecated, as we want to preserve the ability to modify the Tailwind CSS config in Modern.js plugins.Beta Was this translation helpful? Give feedback.
All reactions