我开始了我的第一个纯前端项目。我想将其部署为Java / Maven。因此,我建立了一个正常的战争项目:
│ package.json
│ pom.xml
│ tsconfig.json
│ typings.json
│
│
├───src
│ └───main
│ ├───resources
│ └───webapp
│ │ index.html
│ │
│ ├───app
│ │ app.component.ts
│ │ main.ts
│ │
│ ├───css
│ │ styles.css
│ │
│ └───WEB-INF
│ web.xml
│
我的问题是如何将路径设置为index.html /相对于包的源。json?由于这是一个角度/打字稿项目,因此还有一些打字稿特定的东西。但我的希望是在json包中一劳永逸地设置“源”路径?
我也不确定是否要直接在“ webapp”中部署这些东西,因为有编译步骤。因此,欢迎提供有关如何构建用于Maven / War部署的纯前端项目的任何建议。
为了将NPM与Maven集成,您可以使用frontend-maven-plugin,我认为这将是您进行编译的绝佳工具。
因此,为了一起配置所有内容,您的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>
<groupId>group.id</groupId>
<artifactId>artifact-id</artifactId>
<version>2.0.14-SNAPSHOT</version>
<name>Artifact Name</name>
<packaging>war</packaging>
<!-- Plug-in definition -->
<build>
<plugins>
<!-- frontend-maven plug-in -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.29</version>
<configuration>
<nodeVersion>v5.10.1</nodeVersion>
<npmVersion>3.8.6</npmVersion>
<installDirectory>target</installDirectory>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
<executions>
<!-- install node & npm -->
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<!--npm install -->
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- npm run build -->
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- Maven WAR plug-in -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
如您所见,首先我们定义frontend-maven-plugin的用法:
接下来,有必要定义执行方式:前两个我认为非常简单;最后一个简单的假设,你里面的package.json,有一个剧本叫目标构建将,例如,拨打browserify,以建立一个命令bundle.js文件:
"scripts": {
"build": "browserify src/main/webapp/app.js -o src/main/webapp/modules/bundle.js"
}
在你的情况,而不是app.js,中的package.json将与您的打字稿文件交互。
最后,定义了Maven WAR插件。唯一进行的配置是提及web.xml所在的位置。
注意,按照定义,Maven将打包src / main / webapp目录中的所有内容。因此,如果要排除任何文件(或文件夹),则应使用配置参数<packagingExcludes>:
<!-- Maven WAR plug-in -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
<packagingExcludes>app/**</packagingExcludes>
</configuration>
</plugin>
上面的配置将排除文件夹app。
同样,这是一个起点。在这里,您可以使用Maven来自定义构建您的应用程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句