AWS Elastic Beanstalk运行Grunt任务
我想在弹性beanstalk上运行一个node.js应用程序。 我有一个客户端,通过一个咕噜的工作(玉,less,concat等)构build我从git中排除此文件夹
我可以通过由grunt-cli
执行的grunt-cli
grunt buildClient
来运行它
我在我的包dev-dependencies
添加了grunt
和grunt-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.json
的postinstall
部分放下这个咕噜的工作,但是这也不行。
我如何在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", ... } }