将Yeoman/Brunch工具与Django/Backbone混合应用程序结合使用
Using Yeoman/Brunch tools with a hybrid Django/Backbone app?
我正在构建一个混合web应用程序,Django在后端,Backbone在前端。
结构如下:我在Django模板中生成所有HTML,使用request.is_ajax
来决定返回哪些模板,并根据需要使用Backbone来拉入HTML(我这样做是因为我想支持非JavaScript用户)。
不管怎样,我的问题是这个。随着我的JavaScript代码变得越来越复杂,我希望能够自动执行以下操作:
- 异步JavaScript加载
- 连接和缩小CSS文件
- 连接和缩小JavaScript文件
- JS过梁
我不太担心图像优化或包装管理。按照我的设置,这可能吗?目前它是一个标准的Django应用程序:
/media
/js
main.js <-- Backbone code is in here
/plugins
backbone.js
underscore.js
/css
main.css
results.css
/img
/myapp
admin.py
models.py
views.py
/templates
/myapp
index.html <-- references to all JS and CSS files here
我不确定我是否应该使用Yeoman(或者只是咕哝)或早午餐,或者是否有更简单的方法。无论我使用什么,我都不确定是否可以将其放入js
目录,或者模板的位置是否会使事情复杂化。
目前我知道如何使用require.js异步加载js,但我不知道如何连接、lint等,因此我正在寻找一个工具。也许我应该写一个shell脚本:)
我可以建议从简单的早午餐开始。Brunch比grunt更简单,因为它的插件开箱即用,不需要编写500行代码grunt文件。它也快得多,你的应用程序的重新编译将立即完成。
你的设置应该像这个
public/ # The directory with static files which is generated by brunch.
app.js # Ready to be served via webserver.
app.css # Don’t change it directly, just run `brunch watch --server`.
assets/ # And then all changed files in your app dir will be compiled.
images/
frontend/ # Main brunch application directory. Configurable, of course.
app/ # Your code will reside here.
assets/ # Static files that shall not be compiled
images/ # will be just copied to `public` dir.
views/ # Create any subdirectories inside `app` dir.
file-1.js # JS files will be automatically concatenated to one file.
file-2.js # They will be also usable as modules, like require('file-2').
file-1.css # CSS files will be automatically concatenated to one file.
stuff.css # JS and CSS files may be linted before concatenation.
tpl.jade # You may have pre-compiled to JS templates. Also with `require`.
vendor/ # All third-party libraries should be put here. JS, CSS, anything.
scripts/ # They will be included BEFORE your scripts automatically.
backbone.js
underscore.js
package.json # Contains all brunch plugins, like jshint-brunch, css-brunch.
config.coffee # All params (you can concat to 2, 5, 10 files etc.)
# are set via this config. Just simple, 15 lines-of-code config.
要创建新的应用程序,请查看像基本样板一样的早午餐骨架。选择任何一个,然后使用brunch new --skeleton <url>
,使用brunch watch --server
启动早午餐观察程序,您就准备好了。当你想部署你的应用程序时,只需使用brunch build --optimize
构建一些东西,它会自动缩小文件。
我可以建议从咕哝开始。有满足您所有需求的艰巨任务:
- grunt contrib usemin将用优化的vers替换对原始文件的引用
- grunt contrib uglify将缩小您的JavaScript
- 咕哝的contrib肉糜会缩小你的CSS
- grunt contrib jshint在您的JavaScript文件上运行jshint
- 如果需要,使用requireJs以异步方式加载文件,并使用grunt contrib requireJs将文件编译为一个文件
相关文章:
- 如何通过ibmworklight中的sql适配器从db2中检索或显示html页面上的数据?android混合应用程序开发
- 我想在混合移动应用程序中使用Sqlite插件(Cordova)创建一个示例项目
- D3图表未在Android混合应用程序中显示
- Angular:如何在外部浏览器中打开Angular变量-appgyver混合应用程序
- 服务器使用混合应用程序发送事件
- 在混合应用程序开发中使用本地存储;本地数据库“-危险或有用
- Sqlite在混合应用程序中不工作
- 无法通过salesforce混合应用程序(forceios)调用RESTAPI
- android混合应用程序与数据库的离线连接
- 如何使用业力和ng-scenario测试Angular/Umbraco混合应用程序
- 现在是否可以在Android手机中使用HTML5或混合应用程序读取智能卡
- 如何本地化节点.js应用程序,每个区域设置具有不同的单词位置,混合静态和动态本地化文本
- window.onload() 不会在混合应用程序中触发
- 不能在 AngularJs 混合应用程序上的 youtube api v3 的发布请求中使用访问令牌
- 如何使用cordova和angularjs在混合移动应用程序中上传pdf文件
- 多设备混合应用程序 - 有没有人让 android 的索引数据库插件工作
- 纯 Javascript 代码执行停止混合应用程序中的离子加载指示器
- 混合应用程序:使用 AngularJS 更改 HTTP 用户代理标头
- 将混合android应用程序与mysql连接
- 如何将PayU资金与Cordova应用程序(混合应用程序)集成