Created
April 23, 2014 13:25
-
-
Save TomoyaShibata/11215101 to your computer and use it in GitHub Desktop.
Backbone.jsのtemplateをgruntを使って外部ファイル化 ref: http://qiita.com/bps_tomoya/items/fc7c27a530b8b3954419
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>grunt build | |
Running "jst:dev" (jst) task | |
File jst/template.js created. | |
Done, without errors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="js/template.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exampleView = Backbone.View.Extend({ | |
template: JST['template'] // 元のファイル名から拡張子を省いたもの | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (grunt) { | |
var pkg = grunt.file.readJSON('package.json'); | |
grunt.initConfig({ | |
jst: { | |
options: { | |
processName: function (filename) { | |
return filename.match(/templates\/(.+)\.tmpl$/)[1]; | |
}, | |
processContent: function (src) { | |
return src.replace(/(^\s+|\s+$)/gm, ''); | |
} | |
}, | |
dev: { | |
files: { | |
// 出力先、及びファイル名: [元ファイルのパターン。例では分かりやすくtmpl形式を対象としている] | |
'jst/template.js': ['templates/**/*.tmpl'] | |
} | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-jst'); // プラグインの読み込み | |
grunt.registerTask('build', ['jst']); // タスク登録 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li>listName <%- listName -></li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment