#Importing Tailwind & Material theme into my Storybook within NX namespace.

136 messages ยท Page 1 of 1 (latest)

oak crown
#

Can someone suggest a good solution? I am on the latest NX version.

sturdy spear
oak crown
#

Hello, thank you, the recipes links seems to be dead

#

does it work for you?

sturdy spear
#

Oh shoot, I thought that got fixed.

#

@narrow dome should I stop sharing the link to the addon on the storybook webpage, and share the github link instead?

oak crown
#

ok got it, thanks. hopefully to get some success ๐Ÿ™‚

narrow dome
#

Hey Ian! Yes please โค๏ธ I still need to replace the links so that the addon page can link out

#

@oak crown Let me know if you need a hand ๐Ÿ˜„

#

I know scss and postcss can still be a little fiddly ๐Ÿ˜… I'm trying to simplify it now

#

Is your NX project going to be Angular?

oak crown
#

for now i added styles to project.json under build-storybook > options

naive lintel
oak crown
#

Thanks, already there. Do i need something else for scss?

#

for example i have scss file with imports

#

@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

naive lintel
#

At this point, I'll tag in the addon/recipe author, @narrow dome.

narrow dome
#

๐Ÿ‘‹

#

Can you share your storybook main.js and preview.js files?

oak crown
#

module.exports = {
core: { builder: 'webpack5' },
stories: ['..//*.stories.mdx', '..//*.stories.@(js|jsx|ts|tsx)'],
addons: [
'@storybook/addon-essentials',
'@storybook/addon-links',
'@storybook/addon-interactions',
'@storybook/addon-a11y',
// '@storybook/preset-scss',
// '@storybook/addon-styling',
],
framework: '@storybook/angular',
};

#

preview is empty atm

#

i also modified project.json for that shared library

#

"build-storybook": {
"executor": "@storybook/angular:build-storybook",
"outputs": ["{options.outputDir}"],
"options": {
"outputDir": "dist/storybook/lib-shared",
"configDir": "libs/lib-shared/.storybook",
"browserTarget": "lib-shared:build-storybook",
"compodoc": false,
"styles": [
"styles/default/colors.scss",
"styles/default/material-theme.scss",
"styles/default/tailwind-imports.scss"
]
},
"configurations": {
"ci": {
"quiet": true
}
}
}

narrow dome
#

So preview.js is where you'll want to import that scss file with your tailwind imports

oak crown
#

ok

narrow dome
#

you'll want to import all those scss files

#

(It might not all work out of the box but we'll take it from there :D)

oak crown
narrow dome
#

It's no problem at all, Bio ๐Ÿ˜„ I'm happy to help

oak crown
#

import "styles/default/tailwind-imports.css";

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
expanded: true,
hideNoControlsWarning: true,
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};

#

in preview

#

lets see if works

#

then will try with .scss

narrow dome
#

Funnily enough, I think your scss imports are going to work but your tailwind.css might not ๐Ÿ˜… ๐Ÿ˜‚

oak crown
#

ok kicked a build now, lets see

narrow dome
#

๐Ÿคž

#

The suspense is killing me ๐Ÿ‘€

oak crown
#

it does not import tailwind

#

the rest seems to work by just adding .scss files into the build process in project.json without doing any addons

narrow dome
#

Okay, perfect ๐Ÿ™‚ So that will be because tailwind needs postcss ๐Ÿ™‚

oak crown
#

it didnt work with postcss

narrow dome
#

We'll get it working ๐Ÿ™‚

#

add this into your main.js addons:

{
   name: "@storybook/addon-styling",
   options: {
     postCss: true,
   },
},
oak crown
narrow dome
#

Also add this postcss.config.js file to your project root:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}
oak crown
narrow dome
#

What error(s) do you get?

oak crown
#

no errors

#

just no styles in the preview

narrow dome
#

Interesting! That's okay ๐Ÿ™‚ we'll get it

#

If you look into the dev tools panel in your browser, are there any errors in there?

oak crown
#

btw .scss file didnt work

#

importing as .css

#

i have just for missing svg files, that the next thing i would need to solve.

#

but its unrelated

narrow dome
#

Okay ๐Ÿ™‚

#

Let's see...

oak crown
narrow dome
#

Can you change the import for your tailwind files to this:

@tailwind base;
@tailwind components;
@tailwind utilities;
oak crown
#

ok lets try

#

rebuilding

#

that's how i had it initially

narrow dome
#

brb taking my dogs out ๐Ÿ™‚

oak crown
narrow dome
#

How did it go? Just trying to wrangle in the last dog

oak crown
#

i think i saw the styles appear for a moment and then gone

#

removing stuff from build process

#

rebuilding again

narrow dome
#

Well that sounds like a positive! maybe we're onto something here ๐Ÿ‘€

narrow dome
#

Just checking in ๐Ÿ˜„ how'd it go?

oak crown
#

Hello, sorry was in meetings and lunch break.

#

lemme get back to it

narrow dome
#

It's all good ๐Ÿ‘

oak crown
#

still doesnt work

#

interesting if i put my own styles in that file with imports to tailwind

#

my styles work

narrow dome
#

Yeah, so the postcss setting aren't being applied

#

Oh!

#

Let me see your tailwind.config.js!!!

oak crown
#

ok

#

tailwin.config.js is in application not in the library

#

const { createGlobPatternsForDependencies } = require('@nrwl/angular/tailwind');
const { join } = require('path');

/** @type {import('tailwindcss').Config} /
module.exports = {
content: [
join(__dirname, 'src/**/!(
.stories|*.spec).{ts,html}'),
...createGlobPatternsForDependencies(__dirname),
],
theme: {
extend: {},
fontFamily: {
roboto: ['Roboto', 'sans-serif'],
},
},
plugins: [],
};

#

do i need to include this into main.js somehow?

narrow dome
#

Nope... but without reading the components in your library it won't build your tailwind classes for your library components

oak crown
#

ok, so what do i need to do?

narrow dome
#

Can you copy this file into your library folder?

oak crown
#

NX Generating @nrwl/angular:setup-tailwind

NX The target "build" was not found for project "lib-shared".

If you are using a different build target, please provide it using the "--buildTarget" option.
If the project is not a buildable or publishable library, you don't need to setup TailwindCSS for it.
Pass --verbose to see the stacktrace.

#

ok lemme copy

#

nx + angular libs + storybook + tailwind = is tricky ๐Ÿ™‚

#

copying tailwind.config.js into the root of the library didn't help. What should I try next?

narrow dome
#

Are you trying to use tailwind classes in your library components?

oak crown
#

yes

#

the crazy thing, i see tailwind styles at the very 1st moment after i rebuild the app and it reloads the page

#

then it goes away

narrow dome
#

hmmm okay

oak crown
#

like for a fraction of a second

narrow dome
#

That is odd

oak crown
#

agreed

sturdy spear
#

It might be helpful if you start a new project and slowly try to match your config, and see if you can reproduce the issue

oak crown
narrow dome
#

I was about to ask, what steps can I take to reproduce your NX repro structure

sturdy spear
#

Are you using storyStoreV7: false?

oak crown
#

just one app, one lib that has a storybook

#

and 1 component

#

where do i need to set it?

sturdy spear
#

you shouldn't have to

oak crown
#

i have 6.5+ installed

sturdy spear
#

ah, ok I thought you were on 7.

oak crown
#

nop

narrow dome
#

I'm not super familiar with NX so you'll have to bare with me here. Are you using a package based project or integrated project?

#

Have you got some nx commands I can run to get something pulled together?

oak crown
#

integrated

#

npx create-nx-workspace

#

pick integrated > angular with single app

narrow dome
#

It's creating itself now

oak crown
#

need to install @nrwl/storybook i think

#

i forgot the steps

#

here is my package.json deps:

#

ehh discord doesnt like it

#

and i dont have nitro

narrow dome
#

So NX says you shouldn't need tailwind in a library but it you want the components in your library to use tailwind classes it needs to be in there

#

Do you have a postcss.config.js file in your lib root?

#

I think I know why it wouldn't let you add tailwind to the library... It wants your library to be buildable or publishable

#

Where as for Storybook you typically want to have tailwind rebuild on change so you can see the changes without needing to rebuild the library and relaunch storybook

oak crown
#

ok

narrow dome
#

Okay... so this is clearly a little bit trickier to fiddle with... I might need to work with the NX team on this one