【问题标题】:converted angular 2 web app to mobile app将 Angular 2 Web 应用程序转换为移动应用程序
【发布时间】:2017-02-17 11:10:01
【问题描述】:

我有一个简单的 angular2 应用程序,我想使用 cordova 为这个应用程序创建一个移动应用程序。如何在不使用 ionic 和 nativeScrypte 的情况下将此 Web 应用程序转换为移动应用程序?

【问题讨论】:

标签: cordova angular mobile


【解决方案1】:

无论您的转译源是什么,都将其复制到cordova 的www 文件夹中。

我将根据 Angular CLI 解释这一点。

我创建了两个项目,一个 Angular CLI 和一个 Cordova。

在 Angular CLI 的配置 json 中,我保留了 production o/p Dir -->Cordova 的 www 目录。

然后每当我进行构建 --prod 时,它会自动将转译的 src 保存在 cordova 的 www 中,然后能够进行 cordova 构建。

为了简化过程,我编写了 1 个 cordova 钩子,它在 cordova build/run 之前执行 ng prod build。

const fs = require('fs');
const execSync = require('child_process').execSync;



module.exports = function(context) {
    const basePath = context.opts.projectRoot;
    const baseWWW = basePath + '/www';

process.chdir('../bmi-surgical-app');
console.log(`New directory: ${process.cwd()}`);

    execSync("ng build --prod --base-href .",{stdio:[0,1,2]});

    var files = fs.readdirSync(baseWWW);
    for (var i = 0; i < files.length; i++) {
      if (files[i].endsWith('.gz')) {
        fs.unlinkSync(baseWWW + '/' + files[i]);
      }
    }
    fs.writeFileSync(baseWWW + '/.gitignore', `# Ignore everything in this directory

*
# Except this file
!.gitignore
`);


};

【讨论】:

  • 它可以工作,但移动应用程序总是在加载它不显示任何东西,
  • 它可以工作,但移动应用程序总是在加载它不显示任何东西,它不显示我的应用程序包含的数据
  • 打开浏览器控制台并检查错误控制台显示的错误...我猜你的错误不是正确的基本 href
猜你喜欢
  • 2017-10-11
  • 2016-10-05
  • 1970-01-01
  • 1970-01-01
  • 2022-08-04
  • 2016-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多