多个目录中的指南针源

发布于 2025-01-05 01:55:58 字数 196 浏览 1 评论 0原文

您是否在多个目录中成功编译了 SASS?您可以设置罗盘来递归地监视目录吗?

我已经阅读了有关 add_import_path 的文档,但我真的很感激一些示例代码,因为我(我相当确定)从未编写过一行 ruby​​ 代码。

我问的原因是我有几个共享一些标准 scss 的项目。我希望对共享 scss 的更改能够级联到所有项目。

谢谢。

Have you had success compiling SASS in multiple directories? Can you set up compass to recursively watch a directory?

I have read the documentation on add_import_path, but I would really appreciate some sample code, as I have (I am fairly certain) never written a line of ruby code.

The reason I ask is that I have several projects that share some standard scss. I would like changes to the shared scss to cascade to all projects.

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩余の解释 2025-01-12 01:55:58

假设您有以下目录结构:

project
    |-- config.rb
    +-- apps
        |-- main.scss
        |-- app1
            +-- appst1.scss
        |-- app2
            +-- appst2.scss
        +-- app3
            +-- appst3.scss

然后调整您的 config.rb:

sass_dir = "apps"
add_import_path "apps"
...

并在 main.scss 中包含其他 scss 文件:

@import "app1/appst1";
@import "app2/appst2";
@import "app3/appst3";

Let's say you have the following directroy structure:

project
    |-- config.rb
    +-- apps
        |-- main.scss
        |-- app1
            +-- appst1.scss
        |-- app2
            +-- appst2.scss
        +-- app3
            +-- appst3.scss

Then adjust your config.rb:

sass_dir = "apps"
add_import_path "apps"
...

and in your main.scss include the other scss files:

@import "app1/appst1";
@import "app2/appst2";
@import "app3/appst3";
半夏半凉 2025-01-12 01:55:58

这是我的解决方案,基于两个 Ruby 脚本,支持批处理罗盘编译/监视多个独立的 SASS 项目。

包含 Ruby 文件的文件夹结构:

Root
--compile.rb
--watch.rb
--Module1
----config.rb
----css
----sass
--Module2
----config.rb
----css
----sass
--Module3
----config.rb
----css
----sass

运行 compile.rbwatch.rb,其中几个参数代表包含 config.rb 的模块文件夹的路径> 文件。

即:rubycompile.rb Module1/Module2/Module3/

compile.rb

require 'rubygems'
require 'compass'
require 'compass/exec'

ARGV.each do |arg|
  Compass::Exec::SubCommandUI.new(["compile", arg, "--force"]).run!
end

即: ruby​​ watch.rb Module1/ Module2/ Module3/

watch.rb

require 'rubygems'
require 'compass'
require 'compass/exec'

threads = []
ARGV.each do |arg|
  threads << Thread.new {
    Compass::Exec::SubCommandUI.new(["watch", arg, "--force"]).run!
  }
  sleep(1)
end
threads.each { |thr| thr.join }

请注意,我们需要为每个指南针手表创建一个单独的线程(因为它们是阻塞进程)。 sleep(1) 是必要的,因为 Compass::Exec::SubCommandUI 实际上并不是线程安全的,并且可能在同一模块上运行多个监视,而不是每个监视一个。如果发生这种情况,请尝试增加 sleep 值。

在所有模块中创建类似的 config.rb 文件。您可能必须使用compass init来获取compass识别的第一个config.rb

配置文件

http_path = "/"
css_dir = "css"
sass_dir = "sass"

Here is my solution that supports batch compass compile/watch of multiple independent SASS projects, based on two Ruby scripts.

Folder structure with the Ruby files:

Root
--compile.rb
--watch.rb
--Module1
----config.rb
----css
----sass
--Module2
----config.rb
----css
----sass
--Module3
----config.rb
----css
----sass

Run compile.rb and watch.rb with several arguments representing the paths to your module folders containing the config.rb files.

I.e. : ruby compile.rb Module1/ Module2/ Module3/

compile.rb

require 'rubygems'
require 'compass'
require 'compass/exec'

ARGV.each do |arg|
  Compass::Exec::SubCommandUI.new(["compile", arg, "--force"]).run!
end

I.e. : ruby watch.rb Module1/ Module2/ Module3/

watch.rb

require 'rubygems'
require 'compass'
require 'compass/exec'

threads = []
ARGV.each do |arg|
  threads << Thread.new {
    Compass::Exec::SubCommandUI.new(["watch", arg, "--force"]).run!
  }
  sleep(1)
end
threads.each { |thr| thr.join }

Notice that we need to create a separate thread for each compass watch (since they are blocking processes). sleep(1) is necessary because Compass::Exec::SubCommandUI is not actually thread-safe and might run several watches on the same module, instead of one on each. In case that happens, try increasing the sleep value.

Create a similar config.rb file in all modules. You might have to use compass init to get the a first config.rb that compass recognizes.

config.rb

http_path = "/"
css_dir = "css"
sass_dir = "sass"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文