简体   繁体   English

使用导入的自定义 SCSS 组件编译 Tailwind CSS

[英]Compile Tailwind CSS with imported custom SCSS components

I've got a running Vue app created with Vue CLI 4 and also installed Tailwind CSS with the help of this tutorial .我有一个使用 Vue CLI 4 创建的正在运行的 Vue 应用程序,并且还在本教程的帮助下安装了 Tailwind CSS。 Since I want to put my custom components into single files and write them in SCSS, my tailwind config file looks like由于我想将我的自定义组件放入单个文件并在 SCSS 中编写它们,所以我的 tailwind 配置文件看起来像

// tailwind.scss
@tailwind base;
@tailwind components;
@import '@/assets/scss/components/button.scss';
@tailwind utilities;

While serving the app with vue-cli-service serve or building it with vue-cli-service build works great, I am missing the autocompletion feature of my IntelliJ IDEA for all the tailwind classes so that I don't have to use (even tough great) cheat sheets like this .虽然使用vue-cli-service serve应用程序提供服务或使用vue-cli-service build它效果很好,但我缺少 IntelliJ IDEA 的所有顺风类的自动完成功能,因此我不必使用(甚至艰难的伟大)像这样的备忘单。

My idea is to introduce a npm script that will build the full tailwind.css , so that the IDE can utilize it when autocompleting css classes. My idea is to introduce a npm script that will build the full tailwind.css 8CBA22E28EB17B5F5C6AE2A266AZ , so that the IDE can utilize it when autocompleting css classes. I know that I can manually build such file with npx tailwindcss build tailwind.scss -o tailwind.css .我知道我可以使用npx tailwindcss build tailwind.scss -o tailwind.css手动构建这样的文件。

However, although that gives me autocompletion for the built-in tailwind classes, it of course neither compiles the SCSS in my custom components nor does it resolve the @import at all.然而,虽然这给了我内置顺风类的自动完成功能,但它当然既不会在我的自定义组件中编译 SCSS,也根本不会解析@import A solution could be to 1) resolve the @import , 2) compile the SCSS to CSS and 3) use the aforementioned tailwindcss build to finally build the full tailwind.css .解决方案可能是 1)解析@import ,2)将 SCSS 编译为 CSS 和 3)使用上述 tailwindcss tailwindcss build最终构建完整的 tailwind.ZC7A62 tailwind.css

Since I am very inexperienced with Webpack, I wonder if you can give me some hints of how to achieve this.由于我对 Webpack 非常缺乏经验,我想知道您是否可以给我一些如何实现这一点的提示。 Would you even use Webpack for this task?你甚至会使用 Webpack 来完成这项任务吗?

Webpack is definitely the way to go here, I use this config all the time. Webpack 绝对是 go 的方式,我一直使用这个配置。 See the Tailwind documentation page for setup documentation with webpack有关webpack 的设置文档,请参阅 Tailwind 文档页面

Don't worry about autocomplete for Tailwind, you will learn those classes in no time plus their docs and search function on there are brilliant, no need for external cheatsheets imho.不用担心 Tailwind 的自动完成功能,您将立即学习这些课程以及他们的文档,然后搜索 function 就可以了,恕我直言,无需外部备忘单。

If you're using post-cssimport you need to put the @import statement before everything else.如果您使用的是post-cssimport ,则需要将@import语句放在其他所有内容之前。 Check out https://tailwindcss.com/docs/using-with-preprocessors#build-time-imports查看https://tailwindcss.com/docs/using-with-preprocessors#build-time-imports

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM