2016-11-30 90 views
3

在使用Angular 2 fronend部署基于Java的应用程序时,我遇到了一个问题。在Heroku上部署Java应用程序和Angular2 fronend

我的应用程序需要安装NodeJs,它是“npm install”以从package.json中获取所有依赖关系。 而只有与maven。 Angular2应用程序位于java webapp文件夹中。 我看到buildpack安装它。但他们不工作。例如 这个

https://github.com/Vincit/heroku-buildpack-java-nodejs

它搜索* .ts文件的根,而不是在“Web应用程序” java文件夹。 有没有一些智能buildpacks这样的任务,或其他简单的方法来做到这一点?

预先感谢您!

回答

0

你可以用Heroku对multiple buildpacks on an app的支持来做到这一点。总之,运行:

$ heroku buildpacks:clear 
$ heroku buildpacks:add heroku/nodejs 
$ heroku buildpacks:add heroku/java 

在你的情况,这种情况可能是非常相似的this JHipster example,它使用的Node.js和角度。有几件事情需要考虑:

  • Heroku Node.js buildpack will not install devDependencies by default。您需要将它们移动到dependencies或设置配置变量NPM_CONFIG_PRODUCTION=false
  • 如果您在运行时不需要您的node_modules目录或Node.js运行时,它将使您的应用程序变得巨大。你可以使用Maven删除它们。

下面是一个例子:

<plugin> 
    <artifactId>maven-clean-plugin</artifactId> 
    <version>2.5</version> 
    <executions> 
    <execution> 
     <id>clean-build-artifacts</id> 
     <phase>install</phase> 
     <goals><goal>clean</goal></goals> 
     <configuration> 
     <excludeDefaultDirectories>true</excludeDefaultDirectories> 
     <filesets> 
      <fileset> 
      <directory>node_modules</directory> 
      </fileset> 
      <fileset> 
      <directory>.heroku/node</directory> 
      </fileset> 
     </filesets> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

这在更详细地描述JHipster post

0

我使用这个插件:

https://github.com/eirslett/frontend-maven-plugin

<plugin> 
    <groupId>com.github.eirslett</groupId> 
    <artifactId>frontend-maven-plugin</artifactId> 
    <version>1.0</version> 
    <executions> 
     <execution> 
     <id>install node and npm</id> 
     <goals> 
     <goal>install-node-and-npm</goal> 
     </goals> 
     <configuration> 
     <nodeVersion>v4.4.3</nodeVersion> 
     <npmVersion>3.8.3</npmVersion>          
     </configuration> 
    </execution> 
    <execution> 
     <id>npm install</id> 
     <goals> 
     <goal>npm</goal> 
     </goals> 
     <configuration> 
     <arguments>--strict-ssl=false install</arguments> 
     </configuration> 
     </execution>        
     <execution> 
     <id>npm build prod</id> 
     <goals> 
     <goal>npm</goal> 
     </goals> 
    <configuration> 
    <arguments>run build.prod</arguments> 
    </configuration> 
    </execution> 
    </executions> 
    </plugin> 

NPM build.prod是我一饮而尽任务,建立督促部署和被指定为我的package.json(脚本我使用角2号种子):https://github.com/mgechev/angular-seed

我不得不创建一个任务复制到一个地方,我的Java应用程序使用静态文件:

import * as gulp from 'gulp'; 
let gnf = require('gulp-npm-files'); 
let resourceDest = 'src/main/resources/public'; 

export =() => { 

     gulp.src('**', {cwd:'./dist/prod'}).pipe(gulp.dest(resourceDest)); 
     gulp.src(gnf(), {base:'./'}).pipe(gulp.dest(resourceDest)); 


}; 

这复制我编译的角2 JavaScript到src/main/resources/public