SlideShare a Scribd company logo
Intro to sbt-web 
Asset handling in Play 2.3 
Marius Soutier! 
Freelance Scala Developer 
@mariussoutier
Motivation 
‱ Play’s client-side support not flexible enough, 
too opinionated which technologies it supports 
‱ Can’t keep up with speed of innovation in the 
JavaScript world (see JavaScript drinking game) 
‱ If you can’t beat ‘em, join ‘em 
Adopt Node APIs and make them run on the JVM 
at full speed 
‱ Factor out asset handling into sbt plugins to build 
community independent from Play
Enter sbt-web 
sbt 
sbt-web! 
Project Layout! 
Assets! 
Error Reporting 
sbt-js-engine! 
Execute JavaScript in sbt! 
Trireme / Node / Nashorn 
sbt-js-task! 
Write sbt tasks that execute! 
JavaScript using js-engine! 
WebJars! 
Dependency 
Management 
sbt-web-driver! 
Execute DOM-based JavaScript! 
WebDriver 
- But let’s focus on sbt-web today -
Just Enough sbt 
‱ .sbt and .Scala build files 
‱ Build is an immutable collection of 
key-value pairs (String -> T) 
‱ Tasks are computed settings 
‱ Assign / override values via := 
Setting[Task[T]] 
name := “demo” 
‱ Append / override values via +=, ++= 
Setting[T] 
libraryDependencies += “org.webjars” % 

Scopes 
‱ Settings are scoped by project, configuration, or task; 
default configuration is Global 
‱ Reuse existing settings and scope them for your needs 
compile in Compile 
compile in Test 
sourceDirectory in (Compile, packageBin)
Setting Dependencies 
target 
webTarget 
staging 
Directory 
Settings depend on other settings 
Eases making small changes 
target/web/stage/ 
target := “target” 
webTarget := target.value / “web” 
webStaging := webTarget.value / “stage” 
Global 
Configuration
Inspecting settings 
‱ show <setting-key> to check the value of a setting or 
result of a task 
‱ inspect <setting-key> to understand setting’s 
hierarchy and dependencies 
‱ Use the key, not the name of the val in code 
‱ Access scoped settings via <scope>:<setting-key>
Default Project Layout 
- Play overrides src/main to app -
public 
Global webTarget 
Test Assets 
Directories 
Assets 
Plugin 
source 
Directory 
source 
Managed 
resource 
Directory 
resource 
Managed 
webModules 
Lib 
nodeModule 
Directory 
webModule 
Directory 
nodeModule 
Directory 
public 
source 
Directory 
source 
Managed 
resource 
Directory 
resource 
Managed 
webModule 
Directory 
nodeModule 
Directory 
staging 
Directory
Test Assets 
Tasks 
Assets 
assets 
Global 
node 
Modules 
web 
Modules 
webJars 
stage pipeline 
assets 
assets 

 
compile 
compile test
Source Tasks 
Compile sources to public assets 
Analyze sources 
Integrates with error reporting 
CoffeeScript 
*.coffee 
JavaScript 
LESS 
*.less 
CSS 
src/main/assets/ 
target/ 
web/ 
public/ 
sourceDirectory in Assets public in Assets 
sources in Assets resources-managed/ 
main/ 
resourceManaged in Assets
Asset Pipeline 
Input 
Assets 
Name 
Hashing 
(digest) 
GZip 
Output 
Assets 
Tasks operating on assets sequentially 
Each stage operates on mappings and passes to next one 
pipelineStages := Seq(digest, gzip) 
Play’s Assets router is aware of both digested and gzipped assets
Source Plugins 
sbt-coffeescript Convert CoffeeScript to JavaScript 
sbt-jshint JavaScript linting 
sbt-stylus CSS preprocessor 
sbt-less CSS preprocessor 
sbt-mocha Server-Side JS Testing 
sbt-scalajs Convert ScalaJS to JavaScript (TODO)
Asset Plugins 
sbt-digest Fingerprinting 
sbt-gzip Gzip assets 
sbt-rjs RequireJS integration, minify JavaScript 
sbt-uglify Minify/uglify JavaScript (without RequireJS)
WebJars 
‱ Client-side dependency management, including transitive 
dependencies 
‱ Packed in Jars, resolved like normal dependencies 
by sbt 
libraryDependencies += "org.webjars" % "bootstrap" % "3.2.0" 
‱ sbt-web auto-extracts WebJars to 
target/web/web-modules/lib 
‱ Mapped to jsDelivr CDN automatically by Play’s Assets controller 
‱ Assets in sub-projects are exported as a WebJar
NPM 
‱ Node Package Manager 
‱ Becoming popular for client-side dependencies 
‱ js-engine resolves and auto-extracts dependencies 
defined in package.json 
‱ Disclaimer: Does not seem to work 100% yet
Writing sbt-web tasks 
- Demo -

More Related Content

PDF
Intro to Scala.js - Scala UG Cologne
PDF
Converting a Rails application to Node.js
PDF
Migrating Legacy Data (Ruby Midwest)
PPTX
Dropwizard Internals
PDF
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
PDF
RESTFul development with Apache sling
PDF
Full Stack Scala
PDF
Bye bye $GLOBALS['TYPO3_DB']
Intro to Scala.js - Scala UG Cologne
Converting a Rails application to Node.js
Migrating Legacy Data (Ruby Midwest)
Dropwizard Internals
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
RESTFul development with Apache sling
Full Stack Scala
Bye bye $GLOBALS['TYPO3_DB']

What's hot (20)

PDF
High Performance Ruby: Evented vs. Threaded
PDF
A real-world Relay application in production - Stefano Masini - Codemotion Am...
PPT
Mssql to mysql - Anton Ivanov
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ăƒ©ă‚€ăƒ–ă‚łăƒŒăƒ‡ă‚Łăƒłă‚°
PDF
Django Multi-DB in Anger
PDF
Workload Replay in the Cloud: Secret Weapon for Cloud Migrations
PPTX
MongoDB's New Aggregation framework
ODP
Jenkins Job Builder: our experience
PDF
Configuring a more secure BOSH
PDF
Fast Web Applications Development with Ruby on Rails on Oracle
PPTX
[PL] Code Europe 2016 - Python and Microsoft Azure
PDF
REST Web Service? No, GraphQL please!
ODP
BackboneJS and friends
PDF
RESTful web apps with Apache Sling - 2013 version
PDF
Understanding backbonejs
KEY
HTML5 Hacking - Yahoo! Open Hack Day
PDF
Neoito — React 101
 
PPTX
N:1 Replication meets MHA
 
PDF
React.jsè§ŠăŁăŠăżăŸ ć‰æŸ€ć’ŒéŠ™ć„ˆ
PPTX
Scalable Event Analytics with MongoDB & Ruby on Rails
High Performance Ruby: Evented vs. Threaded
A real-world Relay application in production - Stefano Masini - Codemotion Am...
Mssql to mysql - Anton Ivanov
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ăƒ©ă‚€ăƒ–ă‚łăƒŒăƒ‡ă‚Łăƒłă‚°
Django Multi-DB in Anger
Workload Replay in the Cloud: Secret Weapon for Cloud Migrations
MongoDB's New Aggregation framework
Jenkins Job Builder: our experience
Configuring a more secure BOSH
Fast Web Applications Development with Ruby on Rails on Oracle
[PL] Code Europe 2016 - Python and Microsoft Azure
REST Web Service? No, GraphQL please!
BackboneJS and friends
RESTful web apps with Apache Sling - 2013 version
Understanding backbonejs
HTML5 Hacking - Yahoo! Open Hack Day
Neoito — React 101
 
N:1 Replication meets MHA
 
React.jsè§ŠăŁăŠăżăŸ ć‰æŸ€ć’ŒéŠ™ć„ˆ
Scalable Event Analytics with MongoDB & Ruby on Rails
Ad

Similar to Intro to sbt-web (20)

PDF
Intro to sbt-web
PDF
Play Framework and Activator
KEY
Play Support in Cloud Foundry
PDF
Integrating React.js Into a PHP Application
PDF
3 rad extensibility-srilakshmi_s_rajesh_k
 
PDF
Rad Extensibility - Srilakshmi S Rajesh K
PDF
Web Development using Ruby on Rails
PPTX
Servletarchitecture,lifecycle,get,post
PDF
Meetup developing building and_deploying databases with SSDT
PDF
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
PPT
Maven introduction in Mule
PPT
Maven in Mule
PDF
CTU June 2011 - Things that Every ASP.NET Developer Should Know
 
PPT
PPTX
Servletarchitecture,lifecycle,get,post
PPTX
Servletarchitecture,lifecycle,get,post
PPTX
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...
PPT
Maven
PPTX
Build Fast WordPress Site With Gatsby
PPT
Struts2-Spring=Hibernate
Intro to sbt-web
Play Framework and Activator
Play Support in Cloud Foundry
Integrating React.js Into a PHP Application
3 rad extensibility-srilakshmi_s_rajesh_k
 
Rad Extensibility - Srilakshmi S Rajesh K
Web Development using Ruby on Rails
Servletarchitecture,lifecycle,get,post
Meetup developing building and_deploying databases with SSDT
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Maven introduction in Mule
Maven in Mule
CTU June 2011 - Things that Every ASP.NET Developer Should Know
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...
Maven
Build Fast WordPress Site With Gatsby
Struts2-Spring=Hibernate
Ad

Recently uploaded (20)

PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
top salesforce developer skills in 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
AI in Product Development-omnex systems
PDF
System and Network Administraation Chapter 3
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
ai tools demonstartion for schools and inter college
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PTS Company Brochure 2025 (1).pdf.......
Understanding Forklifts - TECH EHS Solution
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
2025 Textile ERP Trends: SAP, Odoo & Oracle
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Operating system designcfffgfgggggggvggggggggg
top salesforce developer skills in 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
AI in Product Development-omnex systems
System and Network Administraation Chapter 3
How to Choose the Right IT Partner for Your Business in Malaysia
ai tools demonstartion for schools and inter college
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Upgrade and Innovation Strategies for SAP ERP Customers
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Softaken Excel to vCard Converter Software.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 

Intro to sbt-web

  • 1. Intro to sbt-web Asset handling in Play 2.3 Marius Soutier! Freelance Scala Developer @mariussoutier
  • 2. Motivation ‱ Play’s client-side support not flexible enough, too opinionated which technologies it supports ‱ Can’t keep up with speed of innovation in the JavaScript world (see JavaScript drinking game) ‱ If you can’t beat ‘em, join ‘em Adopt Node APIs and make them run on the JVM at full speed ‱ Factor out asset handling into sbt plugins to build community independent from Play
  • 3. Enter sbt-web sbt sbt-web! Project Layout! Assets! Error Reporting sbt-js-engine! Execute JavaScript in sbt! Trireme / Node / Nashorn sbt-js-task! Write sbt tasks that execute! JavaScript using js-engine! WebJars! Dependency Management sbt-web-driver! Execute DOM-based JavaScript! WebDriver - But let’s focus on sbt-web today -
  • 4. Just Enough sbt ‱ .sbt and .Scala build files ‱ Build is an immutable collection of key-value pairs (String -> T) ‱ Tasks are computed settings ‱ Assign / override values via := Setting[Task[T]] name := “demo” ‱ Append / override values via +=, ++= Setting[T] libraryDependencies += “org.webjars” % 

  • 5. Scopes ‱ Settings are scoped by project, configuration, or task; default configuration is Global ‱ Reuse existing settings and scope them for your needs compile in Compile compile in Test sourceDirectory in (Compile, packageBin)
  • 6. Setting Dependencies target webTarget staging Directory Settings depend on other settings Eases making small changes target/web/stage/ target := “target” webTarget := target.value / “web” webStaging := webTarget.value / “stage” Global Configuration
  • 7. Inspecting settings ‱ show <setting-key> to check the value of a setting or result of a task ‱ inspect <setting-key> to understand setting’s hierarchy and dependencies ‱ Use the key, not the name of the val in code ‱ Access scoped settings via <scope>:<setting-key>
  • 8. Default Project Layout - Play overrides src/main to app -
  • 9. public Global webTarget Test Assets Directories Assets Plugin source Directory source Managed resource Directory resource Managed webModules Lib nodeModule Directory webModule Directory nodeModule Directory public source Directory source Managed resource Directory resource Managed webModule Directory nodeModule Directory staging Directory
  • 10. Test Assets Tasks Assets assets Global node Modules web Modules webJars stage pipeline assets assets 
 compile compile test
  • 11. Source Tasks Compile sources to public assets Analyze sources Integrates with error reporting CoffeeScript *.coffee JavaScript LESS *.less CSS src/main/assets/ target/ web/ public/ sourceDirectory in Assets public in Assets sources in Assets resources-managed/ main/ resourceManaged in Assets
  • 12. Asset Pipeline Input Assets Name Hashing (digest) GZip Output Assets Tasks operating on assets sequentially Each stage operates on mappings and passes to next one pipelineStages := Seq(digest, gzip) Play’s Assets router is aware of both digested and gzipped assets
  • 13. Source Plugins sbt-coffeescript Convert CoffeeScript to JavaScript sbt-jshint JavaScript linting sbt-stylus CSS preprocessor sbt-less CSS preprocessor sbt-mocha Server-Side JS Testing sbt-scalajs Convert ScalaJS to JavaScript (TODO)
  • 14. Asset Plugins sbt-digest Fingerprinting sbt-gzip Gzip assets sbt-rjs RequireJS integration, minify JavaScript sbt-uglify Minify/uglify JavaScript (without RequireJS)
  • 15. WebJars ‱ Client-side dependency management, including transitive dependencies ‱ Packed in Jars, resolved like normal dependencies by sbt libraryDependencies += "org.webjars" % "bootstrap" % "3.2.0" ‱ sbt-web auto-extracts WebJars to target/web/web-modules/lib ‱ Mapped to jsDelivr CDN automatically by Play’s Assets controller ‱ Assets in sub-projects are exported as a WebJar
  • 16. NPM ‱ Node Package Manager ‱ Becoming popular for client-side dependencies ‱ js-engine resolves and auto-extracts dependencies defined in package.json ‱ Disclaimer: Does not seem to work 100% yet