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
npmsettings including dependencies and scripts - generating the
package.jsonfor the project - installing dependencies and running npm tasks
npmTargetDir: the root directory of the Node.js project;node_moduleswill be installed here unlessnpmNodeModulesDiris overriden.npmNodeModulesDir: full path to thenode_modulesdir. This can be set separately fromnpmTargetDirin case multiple projects shall share the samenode_modulesdirectory.
Note:npmNodeModulesDirmust be located innpmTargetDiror 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 themainproperty in the generatedpackage.json.npmScripts: sequence of key/value pairs to be added to thescriptssection 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.jsonfile 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.jsonfile. 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.confwill 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.confwill 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 tofastOptJSorfullOptJS).
systemJSConfig: the configuration object used for generating thesystem.config.jsfile (scoped tofastOptJSorfullOptJS).systemJS: generates thesystem.config.jsfile (scoped tofastOptJSorfullOptJS). 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.jsfile.systemjs.meta: additional entries for themetasection in thesystem.config.jsfile.systemjs.packages: additional entries for thepackagessection in thesystem.config.jsfile.systemjs.paths: additional path definitions to be added to thesystem.js.configfile.
Example: see ConfigPlugin.
Configure and run lite-server from within sbt.
liteServerVersion: version oflite-serverto be used.liteServerConfigFile: path to thelite-serverconfig file (scoped tofastOptJSorfullOptJS.
Example:liteServerConfigFile in (Compile, fastOptJS) := baseDirectory.value / "my-config.json"liteServerBaseDir: base directory from which files are served (scoped tofastOptJSorfullOptJS).liteServerIndexFile: path to theindex.htmlfile (scoped tofastOptJSorfullOptJS).liteServerRoutes: entries to be put in the lite-server configroutesobject (scoped tofastOptJSorfullOptJS).
liteServerWriteConfigFile: writes thelite-serverconfiguration file.liteServerWriteIndexFile: writes theindex.htmlfile for the specified stage (fastOptJSorfullOptJS).liteServerStart: starts thelite-serverfor the specified stage (fastOptJSorfullOptJS).
Example:> fastOptJS/liteServerStartliteServerStop: stops thelite-serverfor the specified stage (fastOptJSorfullOptJS).
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 thesasstask (if necessary).sass: compiles scss files located insassSourceDirectories. It's usually not necessary to call this task explicitly, sincefastOptJSandfullOptJSdepend on this task if theSassPluginis 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.conffiles found in libraries (and thenpmProjectConfigFile) and returns the parsed Typesafe Config object.npmProjectConfigString: concatenates all detected configuration files into a single string; useshow npmProjectConfigStringto 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"
}
}
}