com.github.eirslett.maven.plugins.frontend.mojo.WebpackMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of frontend-maven-plugin Show documentation
Show all versions of frontend-maven-plugin Show documentation
This Maven plugin lets you install Node/NPM locally
for your project, install dependencies with NPM,
install dependencies with bower or jspm, run Grunt or gulp tasks,
and/or run Karma tests.
The newest version!
package com.github.eirslett.maven.plugins.frontend.mojo;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.sonatype.plexus.build.incremental.BuildContext;
import java.io.File;
import java.util.Arrays;
import java.util.List;
@Mojo(name="webpack", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public final class WebpackMojo extends AbstractFrontendMojo {
/**
* Webpack arguments. Default is empty (runs just the "webpack" command).
*/
@Parameter(property = "frontend.webpack.arguments")
private String arguments;
/**
* Files that should be checked for changes, in addition to the srcdir files.
* Defaults to webpack.config.js in the {@link #workingDirectory}.
*/
@Parameter(property = "triggerfiles")
private List triggerfiles;
/**
* The directory containing front end files that will be processed by webpack.
* If this is set then files in the directory will be checked for
* modifications before running webpack.
*/
@Parameter(property = "srcdir")
private File srcdir;
/**
* The directory where front end files will be output by webpack. If this is
* set then they will be refreshed so they correctly show as modified in
* Eclipse.
*/
@Parameter(property = "outputdir")
private File outputdir;
/**
* Skips execution of this mojo.
*/
@Parameter(property = "skip.webpack", defaultValue = "${skip.webpack}")
private boolean skip;
@Component
private BuildContext buildContext;
@Override
protected boolean skipExecution() {
return this.skip;
}
@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
if (shouldExecute()) {
factory.getWebpackRunner().execute(arguments, environmentVariables);
if (outputdir != null) {
getLog().info("Refreshing files after webpack: " + outputdir);
buildContext.refresh(outputdir);
}
} else {
getLog().info("Skipping webpack as no modified files in " + srcdir);
}
}
private boolean shouldExecute() {
if (triggerfiles == null || triggerfiles.isEmpty()) {
triggerfiles = Arrays.asList(new File(workingDirectory, "webpack.config.js"));
}
return MojoUtils.shouldExecute(buildContext, triggerfiles, srcdir);
}
}