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

Example of twin inside an nx-workplace #38

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mmmoli
Copy link

@mmmoli mmmoli commented Feb 17, 2021

discussion from #20

See apps/web/pages/index.tsx for example usage.

It's a minimal example that closely follows the rollup + component library in this repo.

What I'd really love, is to demonstrate how the theme can also be customised by introducing a new new lib.

@ben-rogerson thoughts?

@mmmoli mmmoli changed the title Example of twin inside an nx-worksplace Example of twin inside an nx-workplace Feb 17, 2021
@ben-rogerson
Copy link
Owner

Mammoth effort here, great job 💯
I've looked over the code but I think I'll need to fire it up to work out that question.
Will get back to you shortly 👍

@ben-rogerson
Copy link
Owner

What I'd really love, is to demonstrate how the theme can also be customised by introducing a new lib.

Could you let me know what you mean by theme and introducing a new lib?

@mmmoli
Copy link
Author

mmmoli commented Mar 2, 2021

Of course.

Theme
Custom Tailwind Configuration https://tailwindcss.com/docs/theme

"New Lib"
"Library" is nrwl's name for just another package in their monorepo structure. From the docs:

Libraries are not just a way to share code in Nx. They are also useful for factoring out code
into small units with a well-defined public API.

Imagine publishing your Custom Tailwind Configuration to NPM separately,
ready to be pulled into any Tailwind/Twin.macro project later on?

I'm trying to ask: "Shall I put all of that in the example too?"

@anymaniax
Copy link

anymaniax commented Mar 9, 2021

I did a repository with nx, twin.macro and styled-components and I wanted to have a tailwind config by project. To do it I did the following script that I use in the babelMacro config property. Maybe it can help 😀

@mmmoli
Copy link
Author

mmmoli commented Mar 9, 2021

I did a repository with nx, twin.macro and styled-components and I wanted to have a tailwind config by project. To do it I did the following script that I use in the babelMacro config property. Maybe it can help 😀

Interesting!

I got something to work that was way dumber:

// libs/web-ui/babel-plugin-macros.config.js
module.exports = {
  twin: {
    preset: 'emotion',
    config: 'libs/web-ui/tailwind.config.js',
  },
};

// libs/web-ui/tailwind.config.js
module.exports = {
  presets: [require('../tailwind-config')],
};

// libs/tailwind-config/package.json
{
  "name": "@flua/tailwind-config",
  "version": "0.0.1",
  "main": "src/index.js"
}


@ben-rogerson
Copy link
Owner

@mmmoli It would be awesome to add that a tailwind config setup like that to your nx example.

Also - I wonder if we could use path.resolve to avoid specifying the project name:

// libs/web-ui/babel-plugin-macros.config.js
+ const { resolve } = require("path");

module.exports = {
  twin: {
    preset: 'emotion',
+    config: resolve(__dirname, "tailwind.config.js"),
-    config: 'libs/web-ui/tailwind.config.js',
  },
};

// libs/web-ui/tailwind.config.js
module.exports = {
  presets: [require('../tailwind-config')],
};

// libs/tailwind-config/package.json
{
  "name": "@flua/tailwind-config",
  "version": "0.0.1",
  "main": "src/index.js"
}

tw`hover:(scale-105)`,

// Custom color from custom tailwind config
tw`hover:(text-zabadoo)`,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crucially, here's where we're using a custom value set in the theme.

theme: {
extend: {
colors: {
zabadoo: 'blue',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where we're defining a special variable, in this case, a brand colour called "zabadoo".

@ben-rogerson
Copy link
Owner

Hey @mmmoli, thanks for the work on this. I'm planning to take a good look into this in the next few days 👍

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.

3 participants