You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DartSass-Rails无法读取Gem中的admin.scss文件,该如何解决?

问题:Rails 8接入含独立SCSS的Admin Gem时DartSass无法找到文件

我开发了一个Admin Gem,其中包含独立的admin.scss文件,该文件已引入到Gem的admin.html.erb布局中。将此Gem接入使用Propshaft与DartSass的Rails 8应用并运行bin/dev时,出现错误:

Error reading app/assets/stylesheets/admin.scss: Cannot open file.

我尝试过多种方法让DartSass识别Gem中的构建路径,但均无进展。根据DartSass文档说明:

dartsass:build includes application assets paths as Sass load paths.
Assuming the gem has made assets visible to the Rails application, no
additional configuration is required to use them.

我已在Gem的tractor.rb文件中添加了资产路径配置:

require_relative "tractor/version"

module Tractor
  class Error < StandardError; end

  class Engine < ::Rails::Engine
    # Add the assets paths to the engine
    initializer "tractor.assets.paths" do |app|
      app.config.assets.paths << root.join("app", "assets", "stylesheets")
    end

    # Configure Dart Sass builds
    initializer "tractor.assets.configure" do |app|
      # app.config.dartsass.builds = {
      #   "admin.scss" => "admin.css"
      # }
      puts "Dart Sass builds: #{app.config.dartsass.builds.inspect}"
    end

    initializer "tractor.debug" do |app|
      puts "Asset paths: #{app.config.assets.paths.inspect}"
    end
  end
end

但问题仍未解决,请问此需求是否可行?我遗漏了什么配置?

内容的提问来源于stack exchange,提问作者Will

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 03:27:17