[英]Sails.js and Angular.js project structure and configuration for non-SPA case
I am starting a side-project based in Sails to try it. 我正在开始一个基于Sails的侧面项目来尝试它。 Most of the pages are server-side rendered via EJS and don't require javascript on the front-end (my landing page doesn't, my "about" page certainly doesn't etc).
大多数页面都是通过EJS进行服务器端呈现的,并且前端不需要javascript(我的登陆页面没有,我的“关于”页面肯定没有等)。 However, I have a few pages that have quite a lot client-side functionality and I want to use Angular, because I am mostly familiar with that framework.
但是,我有一些页面具有相当多的客户端功能,我想使用Angular,因为我大多熟悉该框架。 The routing to these pages is again handled in the server and there's really no meaning in bundling them as a SPA.
这些页面的路由再次在服务器中处理,将它们捆绑为SPA实际上没有任何意义。
So I am trying to wrap my mind around these concerns: 因此,我试图围绕这些问题进行思考:
/assets/js/dependencies
still the proper place? /assets/js/dependencies
仍然是合适的地方吗? Wouldn't placing them there make the Grunt task inject them in layout.ejs
and thus in every page? layout.ejs
并因此在每个页面中? views/layout.ejs
as a base layout for loading project-wide styles, templates and scripts. views/layout.ejs
作为基础布局来加载项目范围的样式,模板和脚本。 Each page's controller handles injecting the body
part into this layout according to the view "partial" that has been developed for that page. body
部分注入此布局。 Is this view "partial" .ejs file the appropriate place to conditionally load the Angular app files in only the pages that require them? Where to place the Angular app's scripts? 在哪里放置Angular应用程序的脚本?
Is /assets/js/dependencies still the proper place?
/ assets / js / dependencies仍然是合适的地方吗?
No, just put your angular.min.js in your dependencies folder, but not your Angular app's script. 不,只需将angular.min.js放在您的依赖项文件夹中,而不是您的Angular应用程序的脚本。 You need to put all you Angular app in the
assets/js
folder ( or in a sub-folder, but not in dependencies ) 您需要将所有Angular应用程序放在
assets/js
文件夹中(或在子文件夹中,但不在依赖项中)
To be sure that each file of your app will be loaded in the right order (for example you need to load first the Js file which inject your angular app's dependencies), you can modify the tasks/pipeline.js
file, and specify the order you want : You need to modify the jsFilesToInject
array which contains all the Js files to load in the right order. 为了确保您的应用程序的每个文件都以正确的顺序加载(例如,您需要首先加载注入角度应用程序依赖项的Js文件),您可以修改
tasks/pipeline.js
文件,并指定顺序你想要:你需要修改jsFilesToInject
数组,其中包含jsFilesToInject
正确的顺序加载的所有Js文件。
For example for your project : 例如,对于您的项目:
var jsFilesToInject = [
// Load sails.io before everything else
'js/dependencies/sails.io.js',
// loading angularJS
'js/dependencies/angular.min.js',
// all the rest in dependencies
'js/dependencies/**/*.js',
// loading first AngularModule definition
'js/app/app.module.js',
// all the rest of the angular application
'js/app/**/*.js'
];
For your other question I think you need to look at the tasks/config/sails-linker.js
file, that inject all the Js scripts in the <!--SCRIPTS-->
tags in your HTML code. 对于您的其他问题,我认为您需要查看
tasks/config/sails-linker.js
文件,该文件会在HTML代码中的<!--SCRIPTS-->
标记中注入所有Js脚本。
I hope that it will help you and that I'm not too late ! 我希望它会帮助你,我也不会太迟!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.