Unable to get sbt-concat for bundle styles from sbt-sass or sbt-less

(An example project is given) I can’t get sbt-concat work designed to find and concatenate stylesheets that arise due to styles that may arise from preprocessor tasks. In my working application, I'm trying to use it to combine selected output files from sbt-sass . It does not work in the complex setup of this project, so I created a sample project to see if I can make it work at all. It also does not work in the sample project. Here is a build.sbt test project that tries to create several packages, with almost every opportunity I can think of, just see if any of them work ( public Github repo , which you should be able to clone and replicate the problem immediately) :

 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")) ) 

I run ; clean; reload; stage ; clean; reload; stage ; clean; reload; stage from activator for testing. I see source files copied to the target folder with the following results for declared packages:

  • style-group1.css does not exist
  • style-group2.css contains the contents of button.css and core.css
  • style-group3.css contains the contents of core.css and button.css
  • style-group4.css does not exist
  • style-group5.css contains only the contents of core.css
  • style-group6.css contains only the contents of compiled lessStyle.scss
  • style-group7.css contains only the contents of compiled sassStyle.scss
  • style-group8.css does not exist

I do not understand why the 2nd and 3rd cases do not pick up the css files processed by the preprocessor, but the 6th and 7th cases made specially for this. Perhaps, in particular, the result of myPipelineTask shows PathMapping for all source files, as well as the resulting css and sourcemaps from Sass and Less tasks.

+6
source share
1 answer

According to Typesafe support, the source of my problems is the fact that sbt-concat implements its PathFinder logic in such a way that it only receives assets that are literally the same file names as in the source directory. The relative file name sequence works for files in the target directory, but does not have pattern matching. This is pretty unfortunate.

What you need to do to create Seq output files that will exist after compilation using PathFinder in the source directory. So, for .scss files, for example:

 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)) } 

As an additional note, another feature of sbt-concat is that it does not put its new files in its own directory in web-assets:assetsTarget , in order to separate them from artifacts of other stages of the pipeline. Concat.parentDir also not needed because you can just place anything in this variable as a prefix for your package file name.

+3
source

Source: https://habr.com/ru/post/982485/


All Articles