SailsJS到Phonegap? [英] SailsJS to Phonegap?

查看:153
本文介绍了SailsJS到Phonegap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从SailsJS项目创建Phonegap项目。
我发现到目前为止,命令sails build应该生成www文件夹与要导入到Phonegap的文件。我试过,但我得到www文件夹没有索引文件,视图,..它看起来像自定义grunfile是需要得到适当的www文件夹内容。问题是,我不知道如何构建它。这将是伟大的,如果有人可以提供该文件...我相信这将是非常有用的许多...



类似的问题已经在这里描述,没有答案到目前为止。 如何从SailsJS创建phonegap移动应用



提前谢谢!

解决方案

sails build 及其相应的v0.10.x, sails www >

As Ben在对你的问题的评论中说,你的后端Sails代码,包括模型,控制器和服务器端视图,需要一个Node JS服务器来运行。 sails build 只会打包您的前端资产 - 通常最后以 .tmp / public - 放置到 www 文件夹中,该文件夹可能会被删除到PhoneGap应用程序中。



这个想法是,您可以在本地构建您的应用,而不使用服务器端视图(使用 assets / index.html 文件作为起点)而是通过AJAX或套接字请求与Sails后端进行通信。与后端服务器通信的前端JavaScript最好具有单个配置点,可能是 index.html 中的一行代码,用于确定后端服务器的位置测试,可能是 http:// localhost:1337 )。



以这种方式编写并测试所有代码,当你准备好部署到无节点环境(如PhoneGap)时,构建你的 www 目录(获得缩小的优势,任务提供),将配置更改为您将部署Sails后端的位置(例如 http://www.example.com:1234 ),您很好。


I'm trying to create a Phonegap project from SailsJS project. As i found out so far, command "sails build" should generate www folder with files to import to Phonegap. I've tried that, but i get www folder without index file, views,.. It looks like custom grunfile is needed to get appropriate www folder content. The problem is, i don't know how to build it. It would be great if somebody could provide that file... I'm sure it would be very helpful for many...

Similar problem has been described here and got no answers so far. How to make a phonegap mobile app from SailsJS

Thank you in advance!

解决方案

There does seem to be some confusion over what sails build and its v0.10.x equivalent, sails www, are intended for.

As Ben notes in his comment on your question, your backend Sails code, including models, controllers and the server-side views, need a Node JS server to run. sails build only packages up your front-end assets--the stuff that usually ends up in .tmp/public--into a www folder that could, among other things, be dropped into a PhoneGap app.

The idea is that you could build your app locally without server-side views (using an assets/index.html file as your starting point instead), and communicate with the Sails back-end solely via AJAX or socket requests. The front-end Javascript that communicates with the back-end server will ideally have a single configuration point, perhaps a line of code in index.html, that determines the location of the back-end server (for testing, it'd probably be http://localhost:1337).

Write and test all your code this way, and when you're ready to deploy to a Node-less environment (like PhoneGap), build your www directory (getting the benefits of minification that the Sails Grunt tasks provide), change that configuration to the location where you'll be deploying the Sails back-end (e.g. http://www.example.com:1234), and you're good to go.

这篇关于SailsJS到Phonegap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆