Conversation
Thanks a lot for this PR. I'm currently testing this and I'm running into some issues. I'd love to receive some input about them. Also, if it's not too much trouble, from @adamwathan regarding the viability of this PR and about using TailwindCSS with Stencil. Update: Disregard issues 1 and 2. See this post for an in-depth report and why these issues are non-existent. Issue 1 Using the
I have tried adding Issue 2 Applying utilities directly to component classes does not seem to work for me. That is, the Interestingly, extracted utility classes are applied even if I don't add Issue 3 Is there any reason to import import { Config } from '@stencil/core';
import { postcss } from '@stencil/postcss';
import autoprefixer from 'autoprefixer';
import tailwindcss from 'tailwindcss';
import cssnano from 'cssnano';
import purgecss from '@fullhuman/postcss-purgecss';
const purge = purgecss({
content: ['./src/**/*.tsx', './src/index.html'],
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
});
export const config: Config = {
globalStyle: 'src/global/app.css',
globalScript: 'src/global/app.ts',
plugins: [
postcss({
plugins: [
autoprefixer(),
tailwindcss('./tailwind.config.js'),
...(process.env.NODE_ENV === 'production'
? [ purge, cssnano() ]
: [])
],
})
],
outputTargets: [
{
type: 'www',
// comment the following line to disable service workers in production
serviceWorker: null,
baseUrl: 'https://myapp.local/'
}
]
}; I think what's next for me is to clone your stencil-boilerplate repo and see if I can make it work from there. In the meantime, any input would be much appreciated. Update: Did just that. Removing Note that I had to update some dependencies to build the repo, specifically related to jest and @types/jest, due to declaration conflicts. |
@davvelsan Thanks. I've haven't encountered issues 1 or 2. What OS are you using? Re issue 3, I've cleaned up the config file. Thanks. I updated the example to use the latest version of Stencil. Does this fix any of your issues? I'm planning to record to videos about Tailwind, using it with Stencil is one of them. |
@jagreehal Thanks for your quick reply. Sorry, that was not a good report. Your example works perfectly. The problem arised when following the instructions to add TailwindCSS to a new Stencil project. But now I'm mystified. I started writing a report with all the steps to reproduce it and what do think happened... it does work fine. I apologize for wasting your time. It is not a bad lesson for me to learn today: herein lies the importance of writing a proper issue report... I'm going to leave the steps I followed here as a testament to my own stupidity. But consider my main issue (Issue 2) resolved. Resolved/Non-existent IssueThis is here for completeness. Ignore unless looking for amusement. OS Info My dev environment is setup on Windows 10 64bit, running a non-standard WSL2 distro: Arch-Linux. Windows 10 64bit
WSL2 Arch-Linux
# uname -a
Linux 4.19.84-microsoft-standard #1 SMP Wed Nov 13 11:44:37 UTC 2019 x86_64 GNU/Linux Issue Description After following the README instructions on how to add TailwindCSS to a new project, applying utilities directly to component classes does not work. That is:
How to Reproduce Follow the Getting Started guide, selecting a minimal starter app. npm init stencil
> app Update {
"scripts": {
"build": "cross-env NODE_ENV=production stencil build",
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^1.3.0",
"@stencil/postcss": "^1.0.1",
"@types/autoprefixer": "^9.6.1",
"@types/node": "^12.12.21",
"autoprefixer": "^9.7.3",
"cross-env": "^6.0.3",
"cssnano": "^4.1.10",
"serve": "^11.2.0",
"tailwindcss": "^1.1.4"
}
} Update import { Config } from '@stencil/core';
import { postcss } from "@stencil/postcss";
import autoprefixer from "autoprefixer";
import tailwindcss from "tailwindcss";
import cssnano from "cssnano";
import purgecss from "@fullhuman/postcss-purgecss";
const purge = purgecss({
content: ["./src/**/*.tsx", "./src/index.html"],
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
});
export const config: Config = {
globalStyle: 'src/global/app.css',
globalScript: 'src/global/app.ts',
outputTargets: [
{
type: 'www',
serviceWorker: null,
baseUrl: 'https://myapp.local/'
}
],
plugins: [
postcss({
plugins: [
tailwindcss('./tailwind.config.js'),
autoprefixer(),
...(process.env.NODE_ENV === "production" ? [purge, cssnano()] : [])
]
})
]
}; Add TailwindCSS imports to @tailwind base;
@tailwind components;
@tailwind utilities; Add a <div class="text-blue-500">
This text should be blue
</div> Install dependencies, initialize npm install
npx tailwind init
npm run start What is expected The What really happens The |
@jagreehal Thank you very much for your repo and help. I believe I'd have given up on making Stencil and Tailwind work together, were it not for this PR. I think I got a starter app that I can use (link to repo), replicating the starter app from the stencil docs. I have added ESLint support, although it was a bumpy road working around the parser, especially with the vscode extension. If there is anything you like in there, feel free to use as you wish. I'll keep updating it when I start development. I'd like to keep an eye out for any content you release. I'm a big fan of Tailwind and definitely interested in anything typescript-related. |
@davvelsan glad it worked out in the end. I've updated my boilerplate to use eslint too. For this PR I wanted to keep thing minimal as the focus was using Tailwind for styling so purposely excluded tests etc. @adamwathan as mentioned earlier my aim is two record a couple of Tailwind videos which could you when deciding to merge this PR 😉 |
Does anyone have an example of this using sass? |
Changes in syntax are documented in NextJS canary release. See https://github.com/zeit/next.js/pull/10119/files
Updated example for Next.js 9.2
I think the example should at least mention this issue: If someone has a fix for it, even better. |
@jasonhulbert it's a tricky one.. IMO this example should be simple. I think addressing styling for components using Shadow Dom and/or slots could make it complicated and more than just a getting started example. |
}) | ||
] | ||
}; | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced the contents of my stencil.config.js
with the above JS snippet. But when I the run `npm build, I get the following errors:
[ ERROR ] ./src\global\css\app.css
Unable to read css import: @import 'tailwindcss/components';
[ ERROR ] ./src\global\css\app.css
Unable to read css import: @import 'tailwindcss/base';
[ ERROR ] ./src\global\css\app.css
Unable to read css import: @import 'tailwindcss/utilities';
[ ERROR ] postcss: src/global/css/app.css, line: 1: src/global/css/app.css
Unknown word
L1: @import 'tailwindcss/base';
Any ideas what I might be missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that when I replace the contents of src/global/css/app.css
(I decided to put the file in the css
subfolder) with this:
@tailwind base;
@tailwind components;
@tailwind utilities;
then doing run npm build
completes successfully. I found the solution here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the example
@import 'tailwindcss/base'; | ||
@import 'tailwindcss/components'; | ||
@import 'tailwindcss/utilities'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in my previous comment, that CSS snippet failed for me when trying to build, but the following works:
@tailwind base;
@tailwind components;
@tailwind utilities;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just came across the sample files below and found that the sample app.css uses exactly the above as its content :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the example
}) | ||
] | ||
}; | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to update the config snippets with the sample config here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the example
I can't get any of this to work. I followed the very simple steps but keep getting these errors on build:
Any ideas how to get it working? |
@elclanrs I've updated the example to use the latest version of Stencil and update a couple of config files. Please could you try the updated example and let me know if it resolves your issue. |
@jagreehal thank you! I was able to make it work now. |
Closing in favour of #61 |
This PR adds Stencil example showing how to use Tailwind using:
and as an added bonus purgecss for optimised production builds