AWS Elastic Beanstalk运行Grunt任务

我想在弹性beanstalk上运行一个node.js应用程序。 我有一个客户端,通过一个咕噜的工作(玉,less,concat等)构build我从git中排除此文件夹

我可以通过由grunt-cli执行的grunt-cli grunt buildClient来运行它

我在我的包dev-dependencies添加了gruntgrunt-cli

我想在启动应用程序之前运行grunt构build,我已经在.ebextensions/app.config设置了一个configuration

 container_commands: 01_build_client: command: grunt buildClient 

我想我的cwd是/tmp/deployment/application/

但有说Fatal error: Unable to find local grunt 。 我猜grunt-cli已经安装了,但为什么会出现这个错误呢?

我也试过在package.jsonpostinstall部分放下这个咕噜的工作,但是这也不行。

我如何在EBS实例上构build我的咕噜作业?

在Paas上运行Grunt时,最好在本地项目中安装grunt-cli和grunt的本地副本。 这样它总是可用的,是你需要的确切版本。 然后你运行npm install而不是grunt这样你的postinstall可以正常工作。

例如,你的package.json可能是这样的:

 "grunt": "0.4.5", "grunt-cli": "0.1.13", 

您可以首先使用grunt command--gruntfile <pathToGruntfile>选项指定gruntfile的path。 但是,在运行此操作之前,您还需要npm install grunt ,否则您将收到相同的错误。

我刚刚遇到类似的问题,同时试图将webpack捆绑在弹性beanstalk上。 我发现,当弹性beanstalk运行npm安装时,它包含--production标志。 这意味着你需要将你的开发依赖移动到依赖块中。

还有一件事让我意识到,eb似乎并没有运行postinstall脚本,这真的很烦人! 我确实发现它运行的是prestart脚本。

我的package.json文件最终看起来像这样:

 { "name": "app", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "node index.js", "prestart": "node node_modules/webpack/bin/webpack.js" }, "dependencies": { "backbone": "^1.2.1", "backbone.marionette": "^2.4.1", "webpack": "^1.9.10", ... } }