public class Yarn extends Frontend
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());
});
}
Using yarn:
{
on("dev", () -> {
use(new Yarn());
});
}
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 Frontend.onStart(Throwing.Consumer) and
Frontend.onStarted(Throwing.Consumer).
The next example executes two scripts:
{
use(new Npm()
.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()
.onStart(npm -> {
npm.execute("run", "webserver");
});
);
}
Copyright © 2017. All rights reserved.