在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):eirslett/frontend-maven-plugin开源软件地址(OpenSource Url):https://github.com/eirslett/frontend-maven-plugin开源编程语言(OpenSource Language):Java 96.9%开源软件介绍(OpenSource Introduction):frontend-maven-pluginThis plugin downloads/installs Node and NPM locally for your project, runs If you prefer Yarn over NPM for your node package fetching,
this plugin can also download Node and Yarn and then run What is this plugin meant to do?
What is this plugin not meant to do?
Notice: This plugin does not support already installed Node or npm versions. Use the Requirements
InstallationInclude the plugin as a dependency in your Maven project. Change <plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- Use the latest released version:
https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
<version>LATEST_VERSION</version>
...
</plugin>
... UsageHave a look at the example project, to see how it should be set up: https://github.com/eirslett/frontend-maven-plugin/blob/master/frontend-maven-plugin/src/it/example%20project/pom.xml
Recommendation: Try to run all your tasks via npm scripts instead of running bower, grunt, gulp etc. directly. Installing node and npmThe versions of Node and npm are downloaded from https://nodejs.org/dist, extracted and put into a <plugin>
...
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v4.6.0</nodeVersion>
<!-- optional: with node version greater than 4.0.0 will use npm provided by node distribution -->
<npmVersion>2.15.9</npmVersion>
<!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
<downloadRoot>http://myproxy.example.org/nodejs/</downloadRoot>
</configuration>
</plugin> You can also specify separate download roots for npm and node as they are stored in separate repos. In case the root configured requires authentication, you can specify a server ID from your maven settings file: <plugin>
...
<configuration>
<!-- optional: where to download node from. Defaults to https://nodejs.org/dist/ -->
<nodeDownloadRoot>http://myproxy.example.org/nodejs/</nodeDownloadRoot>
<!-- optional: credentials to use from Maven settings to download node -->
<serverId>server001</serverId>
<!-- optional: where to download npm from. Defaults to https://registry.npmjs.org/npm/-/ -->
<npmDownloadRoot>https://myproxy.example.org/npm/</npmDownloadRoot>
</configuration>
</plugin> You can use Nexus repository Manager to proxy npm registries. See https://help.sonatype.com/display/NXRM3/Npm+Registry Notice: Remember to gitignore the Installing node and yarnInstead of using Node with npm you can alternatively choose to install Node with Yarn as the package manager. The versions of Node and Yarn are downloaded from If your project is using Yarn Berry (2.x or above), the Yarn version is handled per project but a Yarn 1.x install is still needed as a "bootstrap".
The plugin will try to detect Have a look at the example <plugin>
...
<execution>
<!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
<configuration>
<nodeVersion>v6.9.1</nodeVersion>
<yarnVersion>v0.16.1</yarnVersion>
<!-- optional: where to download node from. Defaults to https://nodejs.org/dist/ -->
<nodeDownloadRoot>http://myproxy.example.org/nodejs/</nodeDownloadRoot>
<!-- optional: where to download yarn from. Defaults to https://github.com/yarnpkg/yarn/releases/download/ -->
<yarnDownloadRoot>http://myproxy.example.org/yarn/</yarnDownloadRoot>
</configuration>
</plugin> Running npmAll node packaged modules will be installed in the <execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: The default argument is actually
"install", so unless you need to run some other npm command,
you can remove this whole <configuration> section.
-->
<arguments>install</arguments>
</configuration>
</execution> Notice: Remember to gitignore the npxYou can also use <execution>
<id>say hello</id>
<goals>
<goal>npx</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>cowsay hello</arguments>
</configuration>
</execution> Running yarnAs with npm above, all node packaged modules will be installed in the <execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<!-- optional: The default argument is actually
"install", so unless you need to run some other yarn command,
you can remove this whole <configuration> section.
-->
<arguments>install</arguments>
</configuration>
</execution> Yarn with Private RegistryNOTE: if you have a private npm registry that mirrors the npm registry, be aware that yarn.lock includes URLs to the npmjs.org module registry and yarn install will use these paths when installing modules. If you want yarn.lock to use your private npm registry, be sure to run these commands on your local machine before you generate yarn.lock:
This will create URLs in your yarn.lock file that reference your private npm registry. Another way to set a registry is to add a .npmrc file in your project's root directory that contains:
Also you can set a registry using a tag
Running bowerAll bower dependencies will be installed in the <execution>
<id>bower install</id>
<goals>
<goal>bower</goal>
</goals>
<configuration>
<!-- optional: The default argument is actually
"install", so unless you need to run some other bower command,
you can remove this whole <configuration> section.
-->
<arguments>install</arguments>
</configuration>
</execution> Notice: Remember to gitignore the Running GruntIt will run Grunt according to the <execution>
<id>grunt build</id>
<goals>
<goal>grunt</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: if not specified, it will run Grunt's default
task (and you can remove this whole <configuration> section.) -->
<arguments>build</arguments>
</configuration>
</execution> Running gulpVery similar to the Grunt execution. It will run gulp according to the <execution>
<id>gulp build</id>
<goals>
<goal>gulp</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: if not specified, it will run gulp's default
task (and you can remove this whole <configuration> section.) -->
<arguments>build</arguments>
</configuration>
</execution> Running jspmAll jspm dependencies will be installed in the <execution>
<id>jspm install</id>
<goals>
<goal>jspm</goal>
</goals>
<configuration>
<!-- optional: The default argument is actually
"install", so unless you need to run some other jspm command,
you can remove this whole <configuration> section.
-->
<arguments>install</arguments>
</configuration>
</execution> Running Karma<execution>
<id>javascript tests</id>
<goals>
<goal>karma</goal>
</goals>
<!-- optional: the default plase is "test". Some developers
choose to run karma in the "integration-test" phase. -->
<phase>test</phase>
<configuration>
<!-- optional: the default is "karma.conf.js" in your working directory -->
<karmaConfPath>src/test/javascript/karma.conf.ci.js</karmaConfPath>
</configuration>
</execution> Skipping tests: If you run maven with the Ignoring failed tests: If you want to ignore test failures run maven with the Why karma.conf.ci.js? When using Karma, you should have two separate
configurations: Running Karma through Grunt or gulp: You may choose to run Karma directly through Grunt
or through gulp instead, as part of the Running Webpack<execution>
<id>webpack build</id>
<goals>
<goal>webpack</goal>
</goals>
<!-- optional: the default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: if not specified, it will run webpack's default
build (and you can remove this whole <configuration> section.) -->
<arguments>-p</arguments>
</configuration>
</execution> Optional ConfigurationWorking directoryThe working directory is where you've put <plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- optional -->
<configuration>
<workingDirectory>src/main/frontend</workingDirectory>
</configuration>
</plugin> Notice: Npm packages will always be installed in Installation DirectoryThe installation directory is the folder where your node and npm are installed. You can set this property on the different goals. Or choose to set it for all the goals, in the maven configuration. <plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- optional -->
<configuration>
<installDirectory>target</installDirectory>
</configuration>
</plugin> Proxy settingsIf you have configured proxy settings for Maven in your settings.xml file, the plugin will automatically use the proxy for downloading node and npm, as well as passing the proxy to npm commands. Non Proxy Hosts: npm does not currently support non proxy hosts - if you are using a proxy and npm install is not downloading from your repository, it may be because it cannot be accessed through your proxy. If that is the case, you can stop the npm execution from inheriting the Maven proxy settings like this: <configuration>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
</configuration> If you have configured proxy settings for Maven in your settings.xml file, the plugin will automatically pass the proxy to bower commands. If that is the case, you can stop the bower execution from inheriting the Maven proxy settings like this: <configuration>
<bowerInheritsProxyConfigFromMaven>false</bowerInheritsProxyConfigFromMaven>
</configuration> If you want to disable proxy for Yarn you can use <execution>
<id>tests</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>compile</phase>
<configuration>
<yarnInheritsProxyConfigFromMaven>false</yarnInheritsProxyConfigFromMaven>
<arguments>run test</arguments>
</configuration>
</execution>
Environment variablesIf you need to pass some variable to Node, you can set that using the property <configuration>
<environmentVariables>
<!-- Simple var -->
<Jon>Snow</Jon>
<Tyrion>Lannister</Tyrion>
<!-- Var value take from maven properties -->
<NODE_ENV>${NODE_ENV}</NODE_ENV>
</environmentVariables>
</configuration> Ignoring FailureIgnoring failed tests: If you want to ignore test failures in specific execution you can set that using the property <configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration> Skipping ExecutionEach frontend build tool and package manager allows skipping execution. This is useful for projects that contain multiple builds (such as a module containing Java and frontend code). Note that if the package manager (npm or yarn) is skipped, other build tools will also need to be skipped because they would not have been downloaded. For example, in a project using npm and gulp, if npm is skipped, gulp must also be skipped or the build will fail. Tools and property to enable skipping
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论