首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AngularJS JavaScript SDK - Gruntfile插件

AngularJS JavaScript SDK - Gruntfile插件
EN

Stack Overflow用户
提问于 2016-05-13 09:27:20
回答 2查看 95关注 0票数 0

我遵循的是官方的AngularJS Grunt插件的回送文档,在Grunt文件下创建任务的过程中,我面临着一个问题。

文档做得很好,在中如何使用插件部分,它提供了一个很好的实现示例,但是stagingproduction部分的含义还不清楚。

我还对为API提供不同的urlBase感兴趣,因为我的AngularJS应用程序是从不同的地址服务的,所以我添加了apiUrl选项,但是当我从Grunt文件启动loopback_sdk_angular任务时,一切都进行得很顺利,但似乎没有考虑在stagingproduction部分中使用apiUrl选项(这两种方法都尝试过,没有改变)使用var urlBase = '/api'而不是var urlBase = 'http://127.0.0.1:3000/api'构建api.service.js

我的咕噜文件:

代码语言:javascript
复制
grunt.loadNpmTasks('grunt-loopback-sdk-angular');

...
//grunt init config
...

loopback_sdk_angular: {
      services: {
        options: {
          input: 'server/server.js', output: 'client/services/api.services.js'
        }, staging: {
          options: {
            apiUrl: 'http://127.0.0.1:3000/api'
          }
        }
//, production: {
//          options: {
//            apiUrl: 'http://127.0.0.1:3000/api'
//          }
//        }
      }
    }


...

grunt.registerTask('generate-services', ['loopback_sdk_angular']);
//end

请有人解释一下这两个部分的含义,以及我缺少什么使var urlBase假定http://127.0.0.1:3000/api的正确值。

EN

回答 2

Stack Overflow用户

发布于 2016-05-26 12:05:50

请有人解释一下这两个部分的含义,以及我缺少什么来使var urlBase假定http://127.0.0.1:3000/api的正确值?

当我以您的方式配置loopback_sdk_angular插件时,我遇到了同样的问题。但是,当选项和暂存属性直接位于loopback_sdk_angular属性下而不是在服务属性中时,问题就得到了解决。

代码语言:javascript
复制
loopback_sdk_angular: {
    options: {
      input: 'server/server.js', output: 'client/services/api.services.js'
    }, staging: {
      options: {
        apiUrl: 'http://127.0.0.1:3000/api'
      }
    }

回环AngularJS Grunt插件文档中可能有一个小故障。如果您注意到,对环回插件的描述遵循我使用的格式,而且效果很好。然而,示例中的格式并不适用于我们两个。

票数 0
EN

Stack Overflow用户

发布于 2017-01-20 11:06:30

您正在尝试将全局选项添加到loopback_sdk_angular grunt任务中,但是您做的方法是错误的。

  1. 其中,您为所有其他任务传递全局选项配置,并且每个子任务或区段都将在它们中继承此选项。

当每个环境都有一个公共输入和输出文件夹时,非常有用。

代码语言:javascript
复制
    // You were trying to achieve this.....
    loopback_sdk_angular: {
      options: {
        input: 'server/server.js', 
        output: 'client/services/api.services.js'
      }, 
      staging: { 
        //input and ouput are inherited from above global options
        options: {
        apiUrl: 'http://staging.url/api'
      },
      production: { 
        //input and output are inherited from above global options
        options: {
          apiUrl: 'http://production.url/api'
        }
    }
  1. 其中为每个子任务定义了特定于环境的选项。

当您有不同的环境输入和输出文件夹时,非常有用。

代码语言:javascript
复制
    // But you actually did this 
    loopback_sdk_angular: {
      staging: { 
        options: {
          input: 'server/server.js', 
          // Different output folder for staging
          output: 'client/staging/services/api.services.js'
          apiUrl: 'http://staging.url/api'
        }
      },
      production: { 
        options: {
          apiUrl: 'http://production.url/api',
          input: 'server/server.js', 
          // Different output folder for production
          output: 'client/production/services/api.services.js'
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37206236

复制
相关文章

相似问题

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