Plugins for integration of Node.js based build tools with sbt.
Add this to your project/plugins.sbt
addSbtPlugin("de.surfice" % "sbt-node" % "0.0.4")
and then enable the plugins you want to use (see below) for your project(s) in build.sbt
:
lazy val root = project.in(file("."))
.enablePlugins(NpmPlugin, /* ... */)
/* ... */
The following sections list the sbt settings and tasks provided by each plugin.
Note: If a plugin task depends on configuration files generated from settings (e.g. package.json
), then these files will be updated if required, and the tasks using those files (e.g. npmInstall
) will be run automatically.
This is the foundation required by all other plugins, but it can also be used on its own.
It provides integration with the npm
tool:
- defining basic
npm
settings including dependencies and scripts - generating the
package.json
for the project - installing dependencies and running npm tasks
npmTargetDir
: the root directory of the Node.js project;node_modules
will be installed here unlessnpmNodeModulesDir
is overriden.npmNodeModulesDir
: full path to thenode_modules
dir. This can be set separately fromnpmTargetDir
in case multiple projects shall share the samenode_modules
directory.
Note:npmNodeModulesDir
must be located innpmTargetDir
or in any parent directory thereof!npmDependencies
: list of npm dependencies (name and version) the application/ library depends on at run time.
Example:npmDependencies ++= Seq("rxjs" -> "^5.0.1")
npmDevDependencies
: list of npm compile time / development dependencies.
Example:npmDevDependencies ++= "Seq("lite-server" -> "^2.2.2")
npmMain
: value of themain
property in the generatedpackage.json
.npmScripts
: sequence of key/value pairs to be added to thescripts
section in the generatedpackage.json
. Example:
npmScripts ++= Seq("start" -> "lite-server")
will add the following entry to the generatedpackage.json
:
"scripts": { "start": "lite-server" }
npmInstall
: updates thepackage.json
file and installs all dependencies. It is usually not necessary to call this task explicitly, since all tasks requiring npm packages should depend on this task.npmRunScript <NAME>
: runs the npm scriptNAME
(must be defined innpmScripts
). If the script does not stop on its own, it can be killed by pressing RETURN in the sbt console.npmWritePackageJson
: generates the projectpackage.json
file. It's usually not necessary to call this task explicitly, since it is called bynpmInstall
.
The follwing settings can be set by package.conf
files located in any library JAR or in an (optional) project.conf
(see ConfigPlugin):
npm.dependencies
: list of npm package name/version pairs to be added to thenpmDependencies
Note: always add your values to the existing list by referencing{npm.dependencies}
, otherwise the values defined by any otherpackage.conf
will be overwritten (see example under ConfigPlugin).npm.devDependencies
: list of npm package name/version pairs to be added to thenpmDevDependencies
Note: always add your values to the existing list by referencing{npm.devDependencies}
, otherwise the values defined by any otherpackage.conf
will be overwritten (see example under ConfigPlugin).
This plugin generates the system.config.js
files with all necessary mappings for npm packages for use of the System.js module loader.
systemJSFile
: output path for the generatedsystem.config.js
(scoped tofastOptJS
orfullOptJS
).
systemJSConfig
: the configuration object used for generating thesystem.config.js
file (scoped tofastOptJS
orfullOptJS
).systemJS
: generates thesystem.config.js
file (scoped tofastOptJS
orfullOptJS
). It's usually not necessary to call this task explicitly, since it is called by dependent tasks, e.g.liteServerPrepare
.
systemjs.map
: System.js mappings key/value mappings to be added to thesystem.config.js
file.systemjs.meta
: additional entries for themeta
section in thesystem.config.js
file.systemjs.packages
: additional entries for thepackages
section in thesystem.config.js
file.systemjs.paths
: additional path definitions to be added to thesystem.js.config
file.
Example: see ConfigPlugin.
Configure and run lite-server
from within sbt.
liteServerVersion
: version oflite-server
to be used.liteServerConfigFile
: path to thelite-server
config file (scoped tofastOptJS
orfullOptJS
.
Example:liteServerConfigFile in (Compile, fastOptJS) := baseDirectory.value / "my-config.json"
liteServerBaseDir
: base directory from which files are served (scoped tofastOptJS
orfullOptJS
).liteServerIndexFile
: path to theindex.html
file (scoped tofastOptJS
orfullOptJS
).liteServerRoutes
: entries to be put in the lite-server configroutes
object (scoped tofastOptJS
orfullOptJS
).
liteServerWriteConfigFile
: writes thelite-server
configuration file.liteServerWriteIndexFile
: writes theindex.html
file for the specified stage (fastOptJS
orfullOptJS
).liteServerStart
: starts thelite-server
for the specified stage (fastOptJS
orfullOptJS
).
Example:> fastOptJS/liteServerStart
liteServerStop
: stops thelite-server
for the specified stage (fastOptJS
orfullOptJS
).
Compiles scss/sass files to css.
sassTarget
: returns the target directory for compiled sass files (overwrite this task to change the target dir).sassSourceDirectories
: returns a list of source directories to be searched for sass files (overwrite this task to change/ add source directories).sassInputs
: returns all input files that are compiled by thesass
task (if necessary).sass
: compiles scss files located insassSourceDirectories
. It's usually not necessary to call this task explicitly, sincefastOptJS
andfullOptJS
depend on this task if theSassPlugin
is loaded.
TBD
This plugin loads additional configuration values found in any package.conf
contained within a library JAR, or in a project.conf
file located in the project root. The format of these files is HOCON.
This plugin is automatically activated by NpmPlugin or any plugin depending on that.
npmProjectConfigFile
: file from which additional project-specific config values are loaded (default:project.conf
)
npmProjectConfig
: loads allpackage.conf
files found in libraries (and thenpmProjectConfigFile
) and returns the parsed Typesafe Config object.npmProjectConfigString
: concatenates all detected configuration files into a single string; useshow npmProjectConfigString
to view the configuration evaluated bynpmProjectConfig
.
npm {
// add the npm packages `foo` and `bar` to the list of npmDependencies
dependencies = ${npm.dependencies} [
{"foo" = "^0.2.0"}
{"bar" = "^0.3.2"}
]
// add npm package `node-sass` to the list of npmDevDependencies
devDependencies = ${npm.devDependencies} [
{"node-sass" = "^4.5.3"}
]
}
// System.js configuration
systemjs {
// add a mapping for package `foo` to the system.config.js file
// note: the prefix 'npm:' is defined by the SystemJSPlugin and points to the project node_modules dir
map {
"foo" = "npm:/foo/bundles/foo.umd.js"
}
meta {
// use `text_loader` for HTML files
"*.html" {
loader = "text_loader"
}
}
}