我正在与browserify和ui-router
构建一个小的角度的应用程序。因为我不希望使用一台服务器,我想采用了棱角分明的$templateCache
像这样来存储我所有的模板:使用角度模板缓存browserify
exports.templateCache = ["$templateCache", function($templateCache) {
'use strict';
$templateCache.put('partials/someState.html',
"myHtmlCode"
);
}];
要填充缓存,我用咕噜寻找到我的partials
文件夹,抓住所有的HTML并将其加载到缓存与grunt-angular-templates
:
ngtemplates: {
myApp: {
cwd: 'dist/',
src: 'partials/**.html',
dest: 'src/js/templates/templates.js',
options: {
bootstrap: function(module, script) {
return 'exports.templateCache = ["$templateCache", function($templateCache) {\n' +
script +
'}];'
}
}
}
},
然后我用browersify我所有的JS结合在一起:
browserify: {
dist: {
files: {
'dist/js/app.js': [
'src/js/templates/**',
'src/app.js'
],
}
}
},
这是窝国王到目前为止,但这个工作流程对我来说看起来非常不便:我有一个中间步骤,我在我的src
目录中创建templates.js
文件,并且在我的grunt文件中有硬编码的代码。
有没有办法更优雅地做到这一点? browserify是否有内置的解决方案来解决这个问题?
有类似问题的处理。你有没有找到解决方案? – 2014-11-11 21:43:42