public abstract class Frontend extends Object implements Jooby.Module
Run webpack, rollup, gulp , etc...
All this is possible thanks to the frontend library, which download and install node.js locally at your project root. This simplify development and make sure the build works in any environment.
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.
The module automatically sync and install dependencies at startup time.
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).
Execution of arbitrary scripts is available via onStart(Throwing.Consumer)
and onStarted(Throwing.Consumer)
.
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 execute a script without waiting to finish (useful to run background task):
{
use(new Npm("v8.6.0"))
.onStart(npm -> {
npm.execute("run", "webserver");
});
);
}
Modifier and Type | Method and Description |
---|---|
com.typesafe.config.Config |
config() |
void |
configure(Env env, com.typesafe.config.Config conf, com.google.inject.Binder binder)
Configure and produces bindings for the underlying application.
|
Frontend |
installDirectory(Path installDirectory)
Set install directory where to save the node executable (node/node).
|
Frontend |
onStart(org.jooby.funzy.Throwing.Consumer<NodeTask> callback)
Run a node task at application start up time.
|
Frontend |
onStarted(org.jooby.funzy.Throwing.Consumer<NodeTask> callback)
Run a node task after application has been initialized and is ready to serve.
|
Frontend |
workDirectory(Path workDirectory)
Set working directory (location of package.json).
|
public Frontend(String nodeVersion)
public Frontend workDirectory(Path workDirectory)
workDirectory
- Work directory.
public Frontend installDirectory(Path installDirectory)
installDirectory
- Location where to save the node executable (node/node).
public Frontend onStart(org.jooby.funzy.Throwing.Consumer<NodeTask> callback)
callback
- Callback.
public Frontend onStarted(org.jooby.funzy.Throwing.Consumer<NodeTask> callback)
callback
- Callback.
public void configure(Env env, com.typesafe.config.Config conf, com.google.inject.Binder binder) throws Throwable
Jooby.Module
application env
and/or the current application properties available from Config
.
configure
in interface Jooby.Module
env
- The current application's env. Not null.
conf
- The current config object. Not null.
binder
- A guice binder. Not null.
Throwable
- If something goes wrong.
public com.typesafe.config.Config config()
config
in interface Jooby.Module
Copyright © 2019. All rights reserved.