AngularJS + sails.js [英] AngularJS + sails.js

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

问题描述

我开发可以利用前端后端sails.js和AngularJS的应用程序。我以为我会使用角应用文书上士角发生器 https://github.com/yeoman/generator-angular,有一次我与前端逻辑做了,我会用创建一个应用程序的帆,

I am developing an app that can utilize sails.js for back-end and AngularJS for Front-end. I thought that I'll create an Angular App using Yeoman-angular generator https://github.com/yeoman/generator-angular, and once I am done with the front-end logic I'll create a sails app using,


  1. NPM安装-g帆

  2. 帆新的应用程序

然后我就文件传输我所有AngularJS到帆文件夹中。

And then I'll transfer all my AngularJS files to the Sails folder.

但问题是,AngularJS创建创建这样一个文件夹层次结构<一href=\"https://github.com/rishy/angular-jade-stylus-seed\">https://github.com/rishy/angular-jade-stylus-seed以及运行咕噜服务器一DIST文件夹中创建包含最终的量产版本。

But the thing is that AngularJS creates creates a folder hierarchy like this https://github.com/rishy/angular-jade-stylus-seed and on running "grunt server" a "dist" folder is created which contains the final production version.

在另一方面,帆新的应用程序后帆app文件夹层次结构等。

On the other hand, after "sails new app" folder hierarchy for sails app is like.


  • API

    • 适配器/

    • 控制器/

    • 型号/

    • 政策/

    • 服务/


    • 图像/

    • JS​​ /

    • 款式/

    • 的favicon.ico

    • 的robots.txt


    • 主页/

    • 403.ejs

    • 404.ejs

    • 500.ejs

    • layout.ejs

    所以,我的问题是:


    1. 现在,如何转移我的角度文件到该目录下航行,我应该如何组织呢?

    2. 由于帆使用帆举来启动服务器和角度使用咕噜服务器,那些我应该使用来启动服务器为我sailsJs + AngularJs应用程序,怎么样这是创建了DIST文件夹中的哪一个AngularJS后?

    3. 什么变化,将我不得不作出的Gruntfile.js,因为它现在应该从两个角度和帆包含code?

    4. 应该在哪里我把我的不同看法和风格文件,我应该怎么获得这些形式角或帆?

    我觉得既然AngularJS和SailsJs都风靡一时目前很多人都面临这个类似的问题。应该有一个强大的样板创建AngularJS + SailsJS应用程序,这是可悲的是,现在下落不明。

    I think lot of people are facing this similar problem since AngularJS and SailsJs are all the rage currently. There should be a robust boilerplate to create an AngularJS + SailsJS app, which sadly is missing right now.

    推荐答案

    由于帆是一个纯粹的后端架构和角纯粹是前端,他们可以一起很好地工作。它可以得到一个有点混乱,当你把角产生了进去,但这里是基本步骤,如果你要开始与角种子应用和帆v0.10:

    Since Sails is a purely back-end framework and Angular is purely front-end, they can work together nicely. It can get a little confusing when you bring the Angular generator into it, but here are the basic steps if you were to start with the Angular Seed app and Sails v0.10:


    1. 创建与新帆航行应用新对myApp

    2. 全歼了的内容,对myApp /资产文件夹

    3. 的角种子应用文件夹中的内容复制到对myApp /资产

    4. 替换的myapp /视图/ layout.ejs的内容与那些角种子应用程序/ index.html的文件

    5. 剪下所有从 layout.ejs 文件中的非脚本标记的内容(一切后&LT;身体GT; 标记和之前的第一个&LT;脚本&GT; 标签,并用它来代替对myApp /视图/ homepage.ejs的内容

    6. &LT;% - 身体%GT; &LT;身体GT; 在标签 layout.ejs

    1. Create a new Sails app with sails new myApp
    2. Wipe out the contents of the myApp/assets folder
    3. Copy the contents of the Angular Seed app folder into myApp/assets
    4. Replace the contents of myapp/views/layout.ejs with those of the Angular Seed app/index.html file
    5. Cut all of the non-script tag content from the layout.ejs file (everything after the <body> tag and before the first <script> tag and use it to replace the contents of myApp/views/homepage.ejs
    6. Place <%-body%> after the <body> tag in layout.ejs

    您就可以开始与帆解除,你会看到在 HTTP的应用角度服务器://本地主机:1337

    You can then start the server with sails lift and you'll see the Angular app at http://localhost:1337.

    我已经把这个在Github上,以供参考。

    使用这种方法,你不需要做任何的Gruntfile,你将永远不会调用咕噜服务器 - 这是仅用于测试应用角度的测试服务器,你带帆替换。你仍然可以得到哪些手表和同步备份您的前端资产,因为他们改变了帆咕噜同步任务的好处。

    Using this method, you don't need to do anything to the Gruntfile, and you'll never call grunt server--that's solely for testing Angular apps with their test server, which you're replacing with Sails. You'll still get the benefit of the Sails grunt-sync task which watches and syncs-up your front-end assets as they are changed.

    如果你真的想使用约曼角生成器,你可以尝试直接生成一个应用程序到资产风帆应用程序的文件夹,并使用生成从内命令夹。我以前没有使用过,所以我不知道dist文件夹是什么,但似乎这一切都安装有支持测试Web服务器(同样不需要节点模块,因为你有帆)和测试套件(这是总是好的)。我能看到的唯一问题是,如果你需要一些任务在约曼产生Gruntfile。帆处理较少的编译和CSS缩小(在生产模式下),但它并没有对翡翠或手写笔什么,所以你必须对这些任务添加到帆Gruntfile如果你真的需要他们。

    If you really want to use the Yeoman Angular generator, you can try generating an app directly into the assets folder of your Sails app and using the generator commands from within that folder. I haven't used it before, so I don't know what the dist folder is for, but it seems like all of the node modules it installs are there to support the test web server (which again you don't need, since you have Sails) and the test suite (which is always nice). The only issue I can see is if you need some of the tasks in that Gruntfile that Yeoman generates. Sails handles Less compilation and CSS minification (in production mode), but it doesn't do anything with Jade or Stylus, so you'd have to add those tasks to the Sails Gruntfile if you really needed them.

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

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