我想到了RequireJS,但这是推荐的方式吗?或者angularjs是否提供了其他内容以及解释它的位置的任何线索?
拥有所有这些文件也非常适合调试,但是一旦需要生产构建,angularJS会将模块合并到一个文件中并最小化结果吗?
如果有人能解释最好的方法,那将是非常有帮助的.
谢谢
说到文件组织,更容易拥有很多小文件(每个模块可能有一个),但是你面对的问题是:我怎么处理所有这些文件?我如何加载它们?
值得一看的是这两个来源:Brian Ford’s blog和this Github repo.它帮助我改进了我的工作流程并更好地理解/使用Angular模块.
TL; DR
我为我的项目做的是使用Grunt连接(如果需要缩小)所有js文件(以及更多:更少的css编译,资产管理,javascript模板编译).
上面的Github回购中给出了一个很好的例子.
I don’t recommend using RequireJS with AngularJS. Although it’s certainly possible,I haven’t seen any instance where RequireJS was beneficial in practice. [Brian Ford]
文件组织
我的app文件夹如下所示:
www |-dist/ = Created by Grunt. Generated files (served by my web server). |-node_modules/ = node modules (ie. Grunt modules. Grunt is based on NodeJS) |-src/ = My workspace |-test/ = Some tests |-vendor = External libraries (AngularJS,JQuery,Bootstrap,D3,... Whatever you need) |-gruntFile.js = The Grunt configuration file: contains all the jobs for Grunt. |-package.json = App infos + dependencies (Grunt modules) I use (concat,uglify,jshint,...)
所以我工作的所有不同文件都在src文件夹中,然后看起来像这样:
www/src |-app = Folder for my controllers | |-Controller1.js | |-Controller2.js | |-... |-assets = Folder for the static assets (img,css,...) | |-img/ | |-css/ | |-favicon.ico |-common = Folder for the shared modules (directives,resources,services,...) | |-directives | | |-chart.js | | |-map.js | | |-... | |-resources | | |-users.js | | |-another-cool-resource.js | | |-... | |-services | | |-service1.js | | |-... |-views = Folder for my templates | |-profile.tpl.html | |-search.tpl.html | |-... |-index.html = The main and unique html file.
咕噜
然后我使用Grunt将所有内容“编译”到dist文件夹中.
可以在here找到gruntFile的示例.
我有一次性的部署工作和一些观察者的发展.
你需要更多解释吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。