MEANJS样板:在哪里包含自定义javascript文件?

时间:2015-04-15 17:15:42

标签: javascript angularjs meanjs

我开始使用Mean JS样板(ref website),并想知道推荐的地方包含公共自定义javascript,jQuery文件(例如FacebookSDK,jQuery动画,......)。

我假设它将在公共文件夹中的某个位置。默认结构如下:enter image description here

它应该进入模块还是lib文件夹?您能否就每个文件夹的功能提供更多指导?任何指导方针?

1 个答案:

答案 0 :(得分:3)

这是一篇关于Angular app文件夹结构的精彩文章: https://scotch.io/tutorials/angularjs-best-practices-directory-structure

要回答关于jQuery / bootstrap.js等问题的问题,我会把它们放到libs文件夹中。

我现在在我的所有应用中使用此方法。对于你的Angular文件,小应用程序的旧方法可能是这样的:

app/
----- controllers/
---------- mainController.js
---------- otherController.js
----- directives/
---------- mainDirective.js
---------- otherDirective.js
----- services/
---------- userService.js
---------- itemService.js
----- js/
---------- bootstrap.js
---------- jquery.js
----- app.js
views/
----- mainView.html
----- otherView.html
----- index.html

更有效的方式(更具描述性):

app/
----- shared/   // acts as reusable components or partials of our site
---------- sidebar/
--------------- sidebarDirective.js
--------------- sidebarView.html
---------- article/
--------------- articleDirective.js
--------------- articleView.html
----- components/   // each component is treated as a mini Angular app
---------- home/
--------------- homeController.js
--------------- homeService.js
--------------- homeView.html
---------- blog/
--------------- blogController.js
--------------- blogService.js
--------------- blogView.html
----- app.module.js
----- app.routes.js
assets/
----- img/      // Images and icons for your app
----- css/      // All styles and style related files (SCSS or LESS files)
----- js/       // JavaScript files written for your app that are not for angular
----- libs/     // Third-party libraries such as jQuery, Moment, Underscore, etc.
index.html

我在当前项目中使用的内容:
enter image description here