我目前正在尝试学习如何在网络开发项目中实现SASS,但是我正在努力弄清楚如何将我的 .scss
文件正确编译到一个单个 .css中
文件。
当我在终端中运行 sass -version
时,我将接收 1.53.0用dart2js 2.17.3
收集。就扩展而言,我使用的是Glenn Marks的Live Sass编译器,在 settings.json
文件中,我的配置看起来像这样:
{
"liveSassCompile.settings.formats":[
{
"format": "expanded",
"extensionName": ".css",
"savePath": "/css"
},
],
"liveSassCompile.settings.excludeList": [
"**/node_modules/**",
".vscode/**"
],
"liveSassCompile.settings.generateMap": true,
"liveSassCompile.settings.autoprefix": [
"defaults"
]
}
这是我当前的项目目录:
当前项目目录结构
我当前的问题是,每当我单击观看
,我要输出的唯一文件是 main.css
和 main.css.map
,但它创建了 index.css
和<代码> index.css.map 文件。
我正在尝试实现类似于 7-1 SASS架构的内容,并且在每个文件夹中,我创建了一个 index.scs.scss
,该文件将包含每个文件目录,然后将是 @forward
到 main.scss
。
有什么特殊的方法可以避免创建的额外文件?我不太熟悉 npm
,但我听说要学习它以利用SASS而不是使用VS代码扩展,这将是更有益的如果事实证明这种方法更有效,则该方法并将整个扩展程序取消。
感谢您在Advanced方面的帮助,希望我提供足够的信息!
I'm currently trying to learn how to implement SASS into my web development projects but I'm struggling a little bit with figuring out how to properly compile my .scss
files into one single .css
file.
When I run sass --version
in my terminal, I receive 1.53.0 compiled with dart2js 2.17.3
. As far as extensions go, I'm using Live Sass Compiler by Glenn Marks, and within the settings.json
file, my configuration looks like this:
{
"liveSassCompile.settings.formats":[
{
"format": "expanded",
"extensionName": ".css",
"savePath": "/css"
},
],
"liveSassCompile.settings.excludeList": [
"**/node_modules/**",
".vscode/**"
],
"liveSassCompile.settings.generateMap": true,
"liveSassCompile.settings.autoprefix": [
"defaults"
]
}
This is my current project directory:
Current Project Directory Structure
My current issue is that whenever I click Watch Sass
, the only file I want to be output is the main.css
and main.css.map
but it creates an index.css
and index.css.map
file as well.
I'm trying to implement something similar to the 7 - 1 SASS Architecture, and within each of those folders I created an index.scss
that'll contain each file in it's directory, which will then be @forward
to the main.scss
.
Is there any particular way I can avoid the extra files being created? I'm not too familiar with npm
but I've heard it would be more beneficial to learn it in order to utilize SASS as opposed to using a VS Code extension and I'm more than open to taking that approach and scrapping the entire extension as a whole if it proves to be more efficient.
Thank you for your help in advanced, I hope I provided enough information!
发布评论
评论(4)
如果您决定坚持使用我的扩展程序,则可以指定一个文件以输出/观看
livesasscompile.settings.includeitems
设置 - 如下所示,也可能显示出更好的解决方案,并且可以使用一个更好的解决方案,您可以在负面的范围 将所有其他文件视为部分文件。然后,当保存任何SASS文件时,它将触发您的
main.scss.scss
文件的汇编。这是
!()
是负球模式,这意味着如果内部的模式匹配,则忽略它。您可以在
If you decide to stick with my extension then you can specify a single file to output/watch with the
liveSassCompile.settings.includeItems
setting - as shown belowAlternatively, and possibly a better solution, you can use a negative glob expression in the
liveSassCompile.settings.partialsList
to treat every other file as a partial. Then, when any SASS file is saved, it triggers compilation of just yourmain.scss
fileAn example of this would be
**/!(main).scss
. It's the!()
that is the negative glob pattern, it means if the pattern inside matches then ignore it.You can see it action over at https://globster.xyz/. Just use the setup below
Dart Sass配备了一个内置的编译器
只需运行代码
sass -watch sass/main.scss css/main.css
Dart sass comes with an inbuilt compiler
Just run the code
sass --watch sass/main.scss css/main.css
这一条故障可能是您问题的原因。
更改此:
对此:
This one faulty line is probably the reason for your problem.
Change this:
to this:
我只是在这里离开这里,如果有人澄清了@USE和@forward规则的7-1模式在2024年10月的@Import标记为弃用之后。
回答原始问题:
索引scss被编译为单独的CSS文件的唯一原因是命名。如果使用基于文件夹的结构,则每个文件夹都可以具有“聚合”文件类型,其唯一的责任是收集当前文件夹中的所有文件并将其转发。
在根文件夹中,主文件应编译为CSS,因此该文件没有下划线,而其他文件则没有。
因此,只需在您的文件名之前放置一个下划线,为_index.scss。到目前为止,这仍然是部分文件,但是一个特殊的部分文件。
官方文档调用这些文件索引文件:
https://sass-lang.com/documentation/at-rang.com/at-rang.at-rules /use/#index-files
但是,关于7-1模式没有任何解释,因为这只是组织您的SCSS的偏爱。
为此,我发现的最好来源是此仓库( https://github.com/kittygiraudel/kittygiraudel/sass-boilerererplate- )作者:Kitty Giraudel。
值得一提的是,她和Miriam Suzanne写的一本书详细介绍了使用Sass。如果您愿意。
https://www.miriamsuzanne.com/books/books/books/jumpstartsass/
编译器Glen在他的YT频道上有广泛的指南。
I just leave this here, if someone looks clarification how the 7-1 pattern with the @use and @forward rules work, after @import marked deprecated in October 2024.
Answer to the original question:
The only reason why the index.scss is compiled as a seperate css file is the naming. If using a folder based structure then each folder can have an "aggregator" type of file, whose only responsibility is to collect all the files in the current folder and forward them out.
In the root folder the main.scss file should compile to css, hence this file does not have an underscore, while others do.
So just put an underscore before your filename, as _index.scss. As far Sass concern this will still be partial file, but a special partial file.
The official documentation calls these file index files:
https://sass-lang.com/documentation/at-rules/use/#index-files
However there is no explanation about the 7-1 pattern as this is only a preference to organize your scss.
For this the best source I find is this repo (https://github.com/KittyGiraudel/sass-boilerplate) by Kitty Giraudel.
Worth to mention that there is a book written by her and Miriam Suzanne that goes in details of using Sass. If you wish so.
https://www.miriamsuzanne.com/books/jumpstartsass/
About using the Live Sass compiler Glen has an extensive guide on his YT channel.
https://www.youtube.com/watch?v=WV-Fm24IE0s&list=PLhdDmC4kQ8MqhX3RtLqfIwz8oaLut1m5X