【问题标题】:Change host app url before build Cordova Application in Visual Studio 2015在 Visual Studio 2015 中构建 Cordova 应用程序之前更改主机应用程序 url
【发布时间】:2016-07-08 09:22:11
【问题描述】:

我正在使用 Visual Studio 2015 通过本教程使用 Apache Cordova 开发托管 Web 应用程序 http://taco.visualstudio.com/en-us/docs/create-a-hosted-app 对于在 Cordova WebView 中打开的特定应用程序 url,我应该在几个地方(config.xml、index.html、index.js)设置这个 url。这个 url 对于开发和生产环境是不同的。在为生产构建应用程序之前,我应该在几个地方(config.xml、index.html、index.js)替换 url。是否可以自动执行此任务(可能通过 gulp 和 taco-team-build 模块)?

【问题讨论】:

    标签: cordova gulp visual-studio-cordova taco


    【解决方案1】:

    最终我的决定很简单。
    我将开发人员和生产 URL 添加到 config.xmlindex.html

    config.xml

    <allow-navigation href="http://dev/*" />
    <allow-navigation href="http://prod/*" />
    

    index.html

    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: http://dev/ http://prod/ https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
    

    index.js 我创建了返回必要 url 的函数。

    function getConnectionInfo(production: boolean): ConnectionInfo
    {
        if (production)
        {
            return {
                TargetUrl: 'http://prod/',
                UsePassword: false,
                User: '',
                Password: ''
            };
        }
            return {
            TargetUrl: 'http://dev/',
            UsePassword: false,
            User: '',
            Password: ''
        };
    }
    

    如果我构建生产应用程序,我会调用 getConnectionInfo(true);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多