无法让 sbt-concat 捆绑来自 sbt-sass 或 sbt-less 的样式

Cannot get sbt-concat to bundle styles from sbt-sass or sbt-less

(提供的示例项目)我无法获得 sbt-concat to work as designed to find and concatenate stylesheets that result from styles that may be produced from preprocessor tasks. In my production app, I'm trying to use it to bundle select minified output files from sbt-sass. It does not work within the complex setup of that project, so I created an example project to see if I could get it to work at all. It does not work in the example project either. Here is a test project build.sbt that tries to create several bundles, with just about every possibility I can think of, just to see if any of them work (public Github repo,您应该能够克隆并立即复制问题):

import com.typesafe.sbt.web.Import.WebKeys._
import com.typesafe.sbt.web.pipeline.Pipeline

name := """sbt-concat-test"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala, SbtWeb)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  jdbc,
  anorm,
  cache,
  ws
)

resolvers += Resolver.sonatypeRepo("releases")

includeFilter in (Assets, LessKeys.less) := "*.less"

excludeFilter in (Assets, LessKeys.less) := "_*.less"

val myPipelineTask = taskKey[Pipeline.Stage]("Some pipeline task")

myPipelineTask := { mappings => println(mappings); mappings }

pipelineStages := Seq(myPipelineTask, concat)

Concat.groups := Seq(
  "style-group1.css" -> group(sourceDirectory.value  ** "*.css"),
  "style-group2.css" -> group(baseDirectory.value  ** "*.css"),
  "style-group3.css" -> group((sourceDirectory in Assets).value  ** "*.css"),
  "style-group4.css" -> group(target.value  ** "*.css"),
  "style-group5.css" -> group(Seq("core.css", "styles/core.css", "assets/styles/core.css", "app/assets/styles/core.css")),
  "style-group6.css" -> group(Seq("lessStyle.css", "ui/lessStyle.css", "styles/ui/lessStyle.css", "assets/styles/ui/lessStyle.css", "app/assets/styles/ui/lessStyle.css")),
  "style-group7.css" -> group(Seq("sassStyle.css", "ui/sassStyle.css", "styles/ui/sassStyle.css", "assets/styles/ui/sassStyle.css", "app/assets/styles/ui/sassStyle.css")),
  "style-group8.css" -> group(Seq("**/*.css"))
)

我从activator 运行 ; clean; reload; stage 进行测试。我看到资产源文件已复制到 target 文件夹中,声明的包的结果如下:

我不明白为什么第 2 和第 3 种情况不提取预处理器生成的 css 文件,而定制的第 6 和第 7 种情况却可以。也许值得注意的是,myPipelineTask 的结果显示所有源文件的 PathMappings,以及来自 Sass 和 Less 任务的派生 css 和源映射。

根据 Typesafe 支持,我的问题的根源在于 sbt-concat 以这样一种方式实现其 PathFinder 逻辑,即只获取与源中的文件名逐字相同的资产目录。相对文件名序列适用于目标目录中的文件,但没有模式匹配。真是不幸。

有效的是构建一个 Seq 的输出文件,这些文件将存在 post-通过在源目录上使用 PathFinder 进行编译。所以对于 .scss 文件,类似于:

Concat.groups := {
  // Determine the output names of the style files to bundle
  // This is really roundabout because sbt-concat only offers 2 ways of
  // specifying files, relative paths and using a PathFinder, and the
  // latter approach restricts itself to source files instead of output files.
  val sourceDir = (sourceDirectory in Assets).value
  val scssFiles = (sourceDir ** "*.scss").getPaths
  val scssRelativePaths = scssFiles.map(_.stripPrefix(sourceDir.getPath).stripPrefix("/"))
  val outputRelativePaths = scssRelativePaths.map(_.stripSuffix(".scss") + ".min.css")
  Seq("bundle.min.css" -> group(outputRelativePaths))
}

作为旁注,sbt-concat 的另一个怪癖是它不会将其新文件放在 web-assets:assetsTarget 中自己的目录中,以将它们与其他管道阶段的工件分开。 Concat.parentDir 也是不必要的,因为您可以直接将任何您放置在该变量中的内容作为您的包文件名的前缀。