【问题标题】:Compass with multiple input/output folders具有多个输入/输出文件夹的指南针
【发布时间】:2016-09-24 00:58:39
【问题描述】:

我想在一个命令中编译/观看分布在多个文件夹中的 Compass/SCSS 文件。据我所知,没有办法配置多个 SCSS 文件夹,再加上单独的 CSS 输出文件夹。

add_import_path 几乎是我所需要的,但我看不到为每个导入路径设置 sass_dir 的方法。

有没有办法做到这一点?
This Quora answer 说没有,但我仍然抱有希望:)


更新:示例目录结构:

  • users/user1/css/
  • users/user1/css/generated/
  • 用户/user2/css/
  • users/user2/css/generated/
  • 主题/theme1/css/
  • 主题/theme1/css/生成/
  • 主题/theme2/css/
  • 主题/theme2/css/生成/

【问题讨论】:

  • 当然可以使用像Grunt 这样的任务运行器。如果您可以添加一些详细信息,例如目录树以及您想要编译的内容以及它们应该在哪里结束,我将制作一个示例 gruntfile。
  • @steveax 更新了问题。

标签: compass-sass


【解决方案1】:

我不知道你是否想在一个编译好的 CSS 中编译所有这些分散的 SASS 文件。如果是这样,恐怕我不知道如何帮助你。

但是,如果您想要多个文件,一种可能的解决方案是使用 Rake。

如何将您需要的所有监视命令包装在一个 Rake 任务中,然后执行此类任务以使它们立即运行。

耙文件

namespace :stylesheets do
  desc 'Watches dynamic stylesheets for user 1 to compile changes'
  task :watch_user1 do
    puts 'Watching first set of stylesheets...'
    system 'compass watch --sass-dir users/user1/css --css-dir users/user1/css/generated -c config/compass.rb'
  end

  desc 'Watches dynamic stylesheets for user 2 to compile changes'
  task :watch_user2 do
    puts 'Watching second set of stylesheets...'
     system 'compass watch --sass-dir users/user2/css --css-dir users/user2/css/generated -c config/compass.rb'
  end
  desc 'Watches dynamic stylesheet all to compile changes'

  multitask watch_all: ['stylesheets:watch_user1', 'stylesheets:watch_user2'] do
    puts 'watching all...'
  end
end

然后您只需运行多任务rake stylesheets:watch_all,所有子任务都会在线程中运行它们的命令。

这个 rake 任务可以大大改进,因为它们是重复的,并且通过一些约定,您甚至可以通过 .yml 文件对其进行配置,但希望能给您一些关于您可以使用 Rake 做什么的想法。

这里有更多关于 Rakenice tutorial about writing rake tasks 的信息

干杯!

【讨论】:

  • 更新了问题。这看起来不错,即使我几乎没有 Ruby 经验。 system 是异步调用吗?
  • 嗨@Znarkus 我更新了答案,因为我的假设是错误的。感谢您澄清示例。 Ruby Kernel#system 方法不是异步的。但是你总是可以将你需要做的事情分成多个任务,并使用 Rake 使用线程的多任务并行构建它们。查看更新的答案。
【解决方案2】:

您可以从命令行获取单个 scss 文件路径。

prodConfig.rb 示例:

cid = ARGV[0] || "default"
cid = cid.sub(/\.scss$/,'').sub(/^.*\//,'')
puts "making with cid="+cid
http_path ="/fcss/" + cid + "/"
css_dir = "public/fcss/"+cid
sass_dir = "sass"
images_dir = "sass/img"
generated_images_dir="public/fcss/"+cid+"/img"
http_images_path="/fcss/"+cid+"/img/"
output_style = :expanded #: :compressed

运行“compass compile -c sass/prodConfig.rb sass/dynamic/xxx.scss”

现在我们在变量 cid

中的 prodConfig.rb 中有“xxx

【讨论】:

    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 2013-06-11
    相关资源
    最近更新 更多