frontend

frontend

Download and install node.js, install npm, yarn and runs npm, webpack, gulp, grunt and more.

dependency

<dependency>
 <groupId>org.jooby</groupId>
 <artifactId>jooby-frontend</artifactId>
 <version>1.6.6</version>
</dependency>

usage

Using npm:

{
  on("dev", () -> {
    use(new Npm("v8.6.0"));
  });

}

Using yarn:

{
  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:

{ "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 and npm.onStarted.

The next example executes two scripts:

{
  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):

{
  use(new Npm("v8.6.0"))
    .onStart(npm -> {
      npm.execute("run", "webserver");
    });
  );

}

starter project

Checkout the webpack-starter demo project.

That’s all folks!!