我可以在Windows中使用Sass和批处理脚本吗?

时间:2022-02-01 23:16:29

In web projects on my local machine, I'm using a fairly simple Sass setup. In the same folder, I have /scss/style.scss and /css/style.css

在我本地计算机上的Web项目中,我使用了一个相当简单的Sass设置。在同一个文件夹中,我有/scss/style.scss和/css/style.css

So to run Sass while I work I just write this in a Ruby Terminal:

所以在我工作的时候运行Sass我只是在Ruby终端中写这个:

cd "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title"
sass --watch scss/style.scss:css/style.css

Works fine, but it's a little cumbersome, so I'm trying to figure out how to do the equivalent with a batch script. I've tried the following, but it's a complete disaster, and my computer tries to open an infinite amount of Ruby consoles.

工作正常,但它有点麻烦,所以我试图弄清楚如何用批处理脚本做等效的工作。我尝试了以下内容,但这是一场彻底的灾难,我的计算机试图打开无数的Ruby控制台。

cd "C:\Ruby193\bin"
start ruby
cd "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title"
sass --watch scss/style.scss:css/style.css
exit

I think what I need to do is to start Ruby running in the background, rather than open the Ruby exe. Does anyone know how, or is that even how Ruby works? Obviously, I'm new to Sass, Ruby and batch scripts, so any insight you can give me would be a big help, thanks.

我认为我需要做的是在后台启动Ruby,而不是打开Ruby exe。有谁知道如何,或者甚至是Ruby如何工作?显然,我是Sass,Ruby和批处理脚本的新手,所以你能给我的任何见解都会有很大的帮助,谢谢。


EDIT: I got it working like this

编辑:我让它像这样工作

cd "\Ruby193\bin"
sass --watch "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title\scss\style.scss:C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title\css\style.css"

I think it should be neater, and suspect that sass needs to have it's $PATH set.

我认为它应该更整洁,并怀疑sass需要设置$ PATH。


EDIT 2: I set the Path variable for Ruby, using these instructions: http://groups.google.com/group/beginning-rails/browse_thread/thread/1c68665013a60081

编辑2:我使用以下说明为Ruby设置Path变量:http://groups.google.com/group/beginning-rails/browse_thread/thread/1c68665013a60081

In my case, the path I needed to add was C:\Ruby193\bin Now the only line I need, when I have the script in the root of the web project, is:

在我的例子中,我需要添加的路径是C:\ Ruby193 \ bin现在我需要的唯一一行,当我在Web项目的根目录中有脚本时,它是:

sass --watch scss/style.scss:css/style.css

sass --watch scss / style.scss:css / style.css

I could keep the part where I change directory to the location of the folders in if I wanted to have something that can run from anywhere on my computer. However, the fact that the script doesn't specify the project location means I can just copy it into any project where I use the same structure.

如果我想要在我的计算机上的任何地方运行某些东西,我可以保留我将目录更改为文件夹位置的部分。但是,脚本没有指定项目位置的事实意味着我可以将它复制到我使用相同结构的任何项目中。

Worth the effort? In the long run, probably, yeah.

值得努力?从长远来看,可能,是的。

2 个解决方案

#1


4  

Just put your original two commands into your batch file. So the content of the .bat file would be:

只需将原始的两个命令放入批处理文件中即可。所以.bat文件的内容是:

cd "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title"
sass --watch scss/style.scss:css/style.css

Simple as that. A batch file like this just runs each command on each line one after the other, as if you were typing each one individually.

就那么简单。像这样的批处理文件只是依次在每一行上运行每个命令,就好像你是单独输入每个命令一样。

#2


2  

If you're trying to update multiple css files with a batch file like this:

如果您尝试使用如下批处理文件更新多个css文件:

scss A.scss ../CSS/A.css
scss B.scss ../CSS/B.css
echo Done.

...but only the first scss command line executes, and the batch file never completes, i.e. you never see the 'Done.', here is why and how to fix it:

...但只执行第一个scss命令行,批处理文件永远不会完成,即你永远不会看到'完成',这就是为什么以及如何修复它:

scss is actually a buggy batch file that fails to return control to your batch file. I fixed this by bypassing the scss batch file and runing ruby and it's scss gem directly as follows:

scss实际上是一个错误的批处理文件,无法将控制权返回给批处理文件。我通过绕过scss批处理文件并运行ruby来解决这个问题,直接运行rubss和scss gem,如下所示:

ruby C:/Ruby193/bin/scss A.scss ../CSS/A.css
ruby C:/Ruby193/bin/scss B.scss ../CSS/B.css
echo Done.

You'll need to have your path pointed to ruby, or put an absolute path in above.

您需要将路径指向ruby,或在上面放置绝对路径。

#1


4  

Just put your original two commands into your batch file. So the content of the .bat file would be:

只需将原始的两个命令放入批处理文件中即可。所以.bat文件的内容是:

cd "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title"
sass --watch scss/style.scss:css/style.css

Simple as that. A batch file like this just runs each command on each line one after the other, as if you were typing each one individually.

就那么简单。像这样的批处理文件只是依次在每一行上运行每个命令,就好像你是单独输入每个命令一样。

#2


2  

If you're trying to update multiple css files with a batch file like this:

如果您尝试使用如下批处理文件更新多个css文件:

scss A.scss ../CSS/A.css
scss B.scss ../CSS/B.css
echo Done.

...but only the first scss command line executes, and the batch file never completes, i.e. you never see the 'Done.', here is why and how to fix it:

...但只执行第一个scss命令行,批处理文件永远不会完成,即你永远不会看到'完成',这就是为什么以及如何修复它:

scss is actually a buggy batch file that fails to return control to your batch file. I fixed this by bypassing the scss batch file and runing ruby and it's scss gem directly as follows:

scss实际上是一个错误的批处理文件,无法将控制权返回给批处理文件。我通过绕过scss批处理文件并运行ruby来解决这个问题,直接运行rubss和scss gem,如下所示:

ruby C:/Ruby193/bin/scss A.scss ../CSS/A.css
ruby C:/Ruby193/bin/scss B.scss ../CSS/B.css
echo Done.

You'll need to have your path pointed to ruby, or put an absolute path in above.

您需要将路径指向ruby,或在上面放置绝对路径。