问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/23952010/sailsjs-to-phonegap