Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Working with Django
      • Background Jobs in Python
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Scala
  • Using Node.js to Perform JavaScript Optimization for Play and Scala Applications

Using Node.js to Perform JavaScript Optimization for Play and Scala Applications

English — 日本語に切り替える

Last updated April 09, 2020

Table of Contents

  • Using the sbt-heroku plugin
  • Using multiple buildpacks

Many sbt plugins perform operations requiring a JavaScript engine. For example, the sbt-rjs plugin performs RequireJs optimization, and the sbt-uglify plugin performs UglifyJS optimization. By default, these plugins use Trireme, which runs Javascript inside the JVM. The Trireme engine may be sufficient for small operations, but it’s performance can suffer when operating on large numbers of files.

To improve the performance of these plugins, it may be necessary to use a native Node.js engine. If you find that your build process hangs indefinitely during a JavaScript step, then you likely need to change engines. In this article, you’ll learn how to configure your project to install Node.js and use it to execute your JavaScript optimizations for a Play or Scala project.

Using the sbt-heroku plugin

Before going any further, it’s important to note that the sbt-heroku plugin uses the locally generated JavaScript artifacts from your build, and does not require any of the changes describe in this article. If you find that sbt-heroku is a good way for you to deploy your applications, then you can ignore this article. However, if you prefer to use Git based deployment then you will want to read on.

Using multiple buildpacks

In order to use Node.js with Scala on Heroku, you must configure your project to use both the Scala buildpack and the Node.js buildpack. This is done with the heroku buildpacks command.

First, add the Node.js and Scala buildpacks to your application by running this:

$ heroku buildpacks:clear
$ heroku buildpacks:add heroku/nodejs
$ heroku buildpacks:add heroku/scala

Then confirm the execution order by running this command:

$ heroku buildpacks
=== nameless-brushlands-4859 Buildpack
1. heroku/nodejs
2. heroku/scala

This ensures Heroku will run the Node.js buildpack first, and the Scala buildpack second.

In order for the Node.js buildpack to execute, your project must also have a package.json file. In this file, you can define the version of Node.js to install. Create the package.json file in the root of your project and put the following code in it:

{ "engines": { "node": "4.0.0" } }

You can also leave it empty (just {}) to always pick up the latest version.

Then add this file to your Git repository by running the following commands:

$ git add package.json
$ git commit -m "Added package.json"

Finally, configure sbt to use the Node.js engine by setting SBT_OPTS thusly:

$ heroku config:set SBT_OPTS="-Dsbt.jse.engineType=Node"

Now you’re ready to deploy. Run the following command:

$ git push heroku master
[master 6d8842c] redeploy
Counting objects: 1, done.
Writing objects: 100% (1/1), 184 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching custom git buildpack... done
remote: -----> Node.js app detected
remote:
remote: -----> Reading application state
remote:        package.json...
remote:        build directory...
remote:        cache directory...
remote:        environment variables...
remote:
remote:        Node engine:         unspecified
remote:        Npm engine:          unspecified
remote:        Start mechanism:     Procfile
remote:        node_modules source: package.json
remote:        node_modules cached: false
...
remote: -----> Fetching custom git buildpack... done
remote: -----> Play 2.x - Scala app detected
remote: -----> Installing OpenJDK 1.8... done
remote: -----> Priming Ivy cache (Scala-2.11, Play-2.3)... done
remote: -----> Running: sbt update
...
remote:        [info] Done packaging.
remote:        [success] Total time: 4 s, completed Jan 29, 2015 2:51:10 PM
remote: -----> Dropping ivy cache from the slug
remote: -----> Dropping sbt boot dir from the slug
remote: -----> Dropping compilation artifacts from the slug
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 98.8MB
remote: -----> Launching... done, v6
remote:        https://play-node-test.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/play-node-test.git
   99109c2..6d8842c  master -> master

As the deploy process executes, you will see that Heroku installs Node.js (which will generate some warning that you can ignore – these are due to the minimal package.json file). When the sbt process executes it will use the Node.js engine.

For more information on configuring the sbt JavaScript engine, see the sbt-js-engine documentation. For more information on using Scala on Heroku, see the DevCenter documentation for Scala support.

Keep reading

  • Scala

Feedback

Log in to submit feedback.

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences