GithubHelp home page GithubHelp logo

karelcemus / sbt-filter Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 9 KB

Filter plugin for pipeline provided by SbtWeb. Filters input files and enables their removal from the build.

License: Other

Scala 100.00%

sbt-filter's Introduction

SBT Filter plugin filters out files not to be published

Member of SbtWeb plugin pipeline to filter out assets. The intended use is to remove assets from the output package, e.g., *.map, original *.less, unminified files, etc.

This plugin may be used to remove any intermediate or unnecessary assets from the product build of your project. Only assets directly owned by the project can be filtered.

Add the plugin to the project/plugins.sbt of your project:

addSbtPlugin("com.github.karelcemus" % "sbt-filter" % "1.1.0")

Your project's build file also needs to enable sbt-web plugins. For example with build.sbt:

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

The plugin must then be added as a new stage in the asset pipeline.

import com.github.karelcemus.filter.Import._

// either
pipelineStages := Seq( filter )

// or
pipelineStages :=  Seq( rjs, filter, digest, gzip ) 

File Filters

By default, the plugin allows all assets to pass through the pipeline, i.e., includeFilter is set to AllPassFilter and excludeFilter to NothingFilter. The assets must be included in includeFilter and not in excludeFilter, otherwise they are dropped. The plugin is implemented as this: assets.filter( includeFilter ).filterNot( excludeFilter ). This gives you wide range of opportunities to configure, which assets to let through.

For example, to remove the original CoffeeScript and LESS sources from the assets build:

excludeFilter in filter := "*.coffee" || "*.less"

Alternatively, you may wish to remove all JavaScript files except the concatenated and minified main.js produce by the RequireJS plugin:

excludeFilter in filter := "*.js" - "main.min.js"

Another approach is to whitelist all assets to be passed through, but the whitelist must be exhaustive. To do this use includeFilter in filter. You may whitelist more files and then some of them blacklist through excludeFilter. In consequence, the filter plugin lets pass through all whitelisted assets, which are not blacklisted.

PatternFileFilter

SBT comes with several file filter, but does not provide convenient implicits for filtering files by regular expressions. This plugin also provides a filter converting any regex into FileFilter. The filter matches the pattern against file's absolute path.

import com.github.karelcemus.filter.Import._

excludeFilter in filter := ".*/images/sprites/.*".r

Acknowledgement

This implementation is inspired by sbt-filter by @rgcottrell, whose implementation did not work for me.

sbt-filter's People

Contributors

karelcemus avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

mebur

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.