将create-react-app集成到maven构建过程中

时间:2017-07-11 15:52:17

标签: maven reactjs

我正在尝试将最近创建的ReactJs应用程序集成到我的大型maven应用程序的其余部分的构建过程中。我过去为使用npm,Gulp和Bower的AngularJs应用程序做了这个。这次的不同之处在于我使用的是Yarn,还有Facebook的create-react-app基础应用程序,它依赖于'react-scripts'开发依赖项。

以前,构建AngularJs应用程序的maven项目的 pom.xml 看起来如此:

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>myapp</artifactId>
  <packaging>war</packaging>
  <name>MyApp Service</name>
  <description>MyApp Service</description>

  <parent>
    ...
  </parent>

  <profiles>
    <profile>
      <id>exec-unix</id>
      <activation>
        <os>
          <family>unix</family>
        </os>
      </activation>
      <properties>
        <npmexec>npm</npmexec>
        <gulpexec>gulp</gulpexec>
        <bowerexec>bower</bowerexec>
      </properties>
    </profile>
  </profiles>

  <properties>
    <frontendDir>src/main/myappui</frontendDir>
  </properties>

  <dependencies>
    ...
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>src/main/webapp</directory>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>npm install</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <executable>${npmexec}</executable>
              <arguments>
                <argument>install</argument>
              </arguments>
              <workingDirectory>${frontendDir}</workingDirectory>
            </configuration>
          </execution>
          <execution>
            <id>bower install</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <executable>${bowerexec}</executable>
              <arguments>
                <argument>install</argument>
              </arguments>
              <workingDirectory>${frontendDir}</workingDirectory>
            </configuration>
          </execution>
          <execution>
            <id>gulp build</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <executable>${gulpexec}</executable>
              <arguments>
                <argument>prepare-for-maven-war</argument>
              </arguments>
              <workingDirectory>${frontendDir}</workingDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

我不太清楚该怎么做'react-scripts'部分。我尝试添加<yarnexec>yarn</yarnexec>执行yarn installyarn build,但它没有提供所需的结果。

0 个答案:

没有答案