首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在IBM bluemix上部署和运行grunt服务器

在IBM bluemix上部署和运行grunt服务器
EN

Stack Overflow用户
提问于 2016-04-22 03:13:25
回答 1查看 668关注 0票数 0

为了在bluemix上运行一个成功的构建和托管我的网站,我需要做哪些改变?

现在,这是我的Gruntfile.js,manifest.yml和package.json。基本文件夹'app‘是一个角度应用程序-

代码语言:javascript
复制
     module.exports = function(grunt){
          grunt.initConfig({
            connect: {
              server: {
                options: {
                  port: 9000,
                  base: 'app',
                  keepalive: true,
                }
              }
            }
          });
          grunt.loadNpmTasks('grunt-contrib-connect');

          grunt.registerTask('default', ['connect']);
        };

package.json

代码语言:javascript
复制
{
  "name": "dummy",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {"grunt-cli": "^1.2.0",
    "grunt": "^0.4.5",
    "grunt-contrib-connect": "^0.10.1"
  }

}

manifest.yml

代码语言:javascript
复制
---
applications: #Reference http://docs.cloudfoundry.com/docs/using/deploying-apps/manifest.html
- name: dummy #Application Name. Unique to the user's Space
  memory: 256M #The maximum memory to allocate to each application instance
  instances: 1 #The number of instances of the application to start
  path: ./ #Path to the application to be pushed
  command:  npm install && node_modules/.bin/grunt serve #The command to use to start the application
EN

回答 1

Stack Overflow用户

发布于 2016-04-24 18:08:32

在使用节点应用程序和Bluemix时,很少有建议:

  1. 要启动节点应用程序,建议使用npm start并在package.json中指定脚本。
  2. 如果您的应用程序需要构建资产,请在postinstall脚本中指定如何在package.json中这样做。例如,如果您正在使用大口吞下,并且您的主要任务是build,那么您将得到如下内容: “后安装”:“吞咽构建”
  3. 在Bluemix中运行时,VCAP_APP_HOSTVCAP_APP_PORT将拥有运行应用程序的主机和端口。

以下文件具有上面提到的修补程序:

manifest.yml

代码语言:javascript
复制
---
applications:
- name: dummy-kartik-yadav
  memory: 512M
  instances: 1
  path: .
  command: npm start

package.json

代码语言:javascript
复制
{
  "name": "dummy",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node_modules/.bin/grunt serve",
    "postinstall": "console.log('build ui assets like js, css, html...')"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "grunt-cli": "^1.2.0",
    "grunt": "^0.4.5",
    "grunt-contrib-connect": "^0.10.1"
  }
}

gruntfile.js

代码语言:javascript
复制
module.exports = function(grunt){
  grunt.initConfig({
    connect: {
      server: {
        options: {
          port: process.env.VCAP_APP_PORT || 9000, # listen to the port that bluemix will assign you
          base: 'app',
          keepalive: true
        }
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.registerTask('default', ['connect']);
};

完成上述更改后,打开项目文件夹并运行npm start。如果它在当地有效的话,它将在布卢米克斯。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36784165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档