简体   繁体   English

空样式 (.css/.scss) 文件

[英]Empty style (.css/.scss) files

When I create Angular application, I am using CLI for generating components.当我创建 Angular 应用程序时,我使用 CLI 来生成组件。 After certain time of developing app I have style file for every component but major part of them are empty.在开发应用程序一段时间后,我为每个组件都有样式文件,但其中大部分是空的。

When I check sonar I have Code smells in empty style files:当我检查声纳时,我在空样式文件中有代码气味:

  • Remove this empty stylesheet.删除这个空的样式表。
  • Add an empty new line at the end of this file.在此文件的末尾添加一个空的新行。

Should I remove sonar rules or I must delete all empty style files in project and recreating them in next versions of project when I need them for component styling?我应该删除声纳规则还是必须删除项目中的所有空样式文件并在需要它们进行组件样式时在项目的下一个版本中重新创建它们? What are best practices?什么是最佳实践?

For me, you can let the CSS / SCSS files empty.对我来说,你可以让 CSS / SCSS 文件为空。 Just because after the build everything around styling will be minified and contained the "styles.js" file.只是因为在构建之后,样式的所有内容都将被缩小并包含“styles.js”文件。 So, even if it's a bit ugly to see all these empty files in dev mode, the compiler will solve your probelm by itself所以,即使在开发模式下看到所有这些空文件有点难看,编译器也会自己解决你的问题

this is a screen of your project after build :这是构建后项目的屏幕:

在此处输入图片说明

The main question is: empty scss files... What are best practices ?主要问题是:空 scss 文件...最佳实践是什么?

Empty files is a project is a bad practice .空文件是一个项目是不好的做法 no one like to have useless files in their file browser.没有人喜欢在他们的文件浏览器中有无用的文件。

I am against @AbhishekAnand answer "the compiler will solve your probelm by itself":我反对@AbhishekAnand 回答“编译器会自己解决你的问题”:

The compiler did not solve the problem for me, the empty files are uglier and I still can't tell the benefits of minifying an empty files .编译器没有为我解决问题,空文件更丑,我仍然无法说出缩小空文件的好处。

My opinion is to remove the " styleUrls " from the component , delete the empty scss and create it when you need it.我的意见是从组件中删除“ styleUrls ”,删除空的 scss 并在需要时创建它。

It will feel good like you just loose weight!感觉就像你刚刚减肥一样好!

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

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