[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.jooby/jooby-frontend/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.jooby/jooby-frontend) [![javadoc](https://javadoc.io/badge/org.jooby/jooby-frontend.svg)](https://javadoc.io/doc/org.jooby/jooby-frontend/1.4.1) [![jooby-frontend website](https://img.shields.io/badge/jooby-frontend-brightgreen.svg)](http://jooby.org/doc/frontend) # frontend Download and install node.js, install npm, yarn and runs npm, webpack, gulp, grunt and more. ## dependency ```xml org.jooby jooby-frontend 1.4.1 ``` ## usage Using npm: ```java { on("dev", () -> { use(new Npm("v8.6.0")); }); } ``` Using yarn: ```java { on("dev", () -> { use(new Yarn("v8.6.0", "v1.1.0")); }); } ``` > **NOTE**: The module must be used in development only. That's why we wrap the module installation using the environment predicate. In order to build a production version, you need to configure a build time process. The frontend maven plugin does this job for maven projects. If you are a Gradle user, you might want to try the gradle-node-plugin. ## install phase The module automatically sync and install dependencies at startup time. ## default task The module runs ```npm run build``` or ```yarn run build``` at startup time (after install phase). This mean your ```package.json``` must defines a ```build``` script, like: ```json { "scripts": { "build": "webpack" } } ``` The default task is always executed, unless you define one or more custom tasks (see next). ## custom task Execution of arbitrary scripts is available via [npm.onStart](/apidocs/org/jooby/frontend/Frontend.html#onStart-org.jooby.funzy.Throwing.Consumer-) and [npm.onStarted](/apidocs/org/jooby/frontend/Frontend.html#onStarted-org.jooby.funzy.Throwing.Consumer-). The next example executes two scripts: ```java { use(new Npm("v8.6.0")) .onStart(npm -> { npm.executeSync("run", "local"); npm.executeSync("run", "next"); }); ); } ``` The next example executes a script without waiting to finish (useful for background tasks): ```java { use(new Npm("v8.6.0")) .onStart(npm -> { npm.execute("run", "webserver"); }); ); } ``` ## starter project Checkout the [webpack-starter](https://github.com/jooby-project/webpack-starter) demo project. That's all folks!!