在Angular 13制作中,尾风不建立课程
在生产中建立时,我很难赢得逆风。我跟随 Angular Guide 和tailwind在服务时工作正常,但是在构建应用程序时却没有识别HTML文件中的任何类,因此
在构建时不会将它们包括在构建中:警告 - 源文件中未检测到实用程序类。如果这是出乎意料的,请仔细检查
content 在您的尾风CSS配置中。
版本:
- Angular CLI:13.3.2
- Angular:13.3.2
- 节点:16.15.0:16.15.0
- 软件包:NPM:NPM 7.10.0
- OS:Win32 x64
- tailwind:3.0.24
tailwind.config.js 看起来像这样的:
module.exports = {
content: ['./src/**/*.html'],
theme: {
extend: {},
},
plugins: [],
};
类的顶部。
/* You can add global styles to this file, and also import other style files */
@tailwind base;
@tailwind components;
@tailwind utilities;
tailwind Imports位于 styles.scss.scss 之 创建了 Postcss配置文件,因为我不确定在引擎盖下的角度汇编以及是否有必要。
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
我尝试
- 返回到tailwind 2,然后将
内容
更改为purge
(使用启用的内容和设置为true。不起作用) - 删除Angular Material CSS进口。 (无法使用)
- 更改配置
content
以包括所有内容('./*//*。{html,ts}'
- 不起作用) - 更改config
content
要包含特定文件('./ src/app/app.component
- 。但我不想这样做。)
- 使用CLI
NPX tailwindcss -o /output.css < /code>(正常工作。)
关于我可能做错什么的想法?谢谢!
I'm having trouble getting Tailwind to work when building in production. I followed the Angular guide and tailwind works fine when serving but when building the app it doesn't recognize any of the classes from HTML files and therefore doesn't include them in the build
When building I get this message: warn - No utility classes were detected in your source files. If this is unexpected, double-check the
contentoption in your Tailwind CSS configuration.
versions:
- Angular CLI: 13.3.2
- Angular: 13.3.2
- Node: 16.15.0
- Package Manager: npm 7.10.0
- OS: win32 x64
- Tailwind: 3.0.24
tailwind.config.js looks like this:
module.exports = {
content: ['./src/**/*.html'],
theme: {
extend: {},
},
plugins: [],
};
tailwind imports are at the top of styles.scss like so:
/* You can add global styles to this file, and also import other style files */
@tailwind base;
@tailwind components;
@tailwind utilities;
I also created a Postcss config file because I wasn't sure how Angular compiled under the hood and if it was necessary or not.
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
Things I have tried
- Going back to Tailwind 2 and changing
content
in the config file topurge
(using content and setting enabled to true. Didn't work) - Removing angular material css imports. (Didn't work)
- Changing the config
content
to include everything ('./**/*.{html,ts}'
- didn't work) - Changing the config
content
to include specific files ('./src/app/app.component.{html,ts}'
- didn't work) - Adding safelist classes (Works, but I don't want to do that.)
- Use CLI
npx tailwindcss -o /output.css
(Works fine.)
Any Ideas about what I might be doing wrong? Thanks all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够解决这个问题。我从
dist
文件夹中的构建脚本中调用ng构建
。 tailwind.config.js中的内容路径并未从项目的根部看,它从命令到命令的词根中查找文件。因此,为了定位
/src/app/*
,我必须像这样上升一个级别:../ src/**/*。html
I was able to figure this out. I calling
ng build
from a build script that I had in thedist
folder. The content path in tailwind.config.js doesn't look from the root of the project, it looks for files from the root of wherever the command is called from.So in order to target
/src/app/*
I had to go up one level like so:../src/**/*.html