Gruntfile.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * grunt-angular-templates
  3. * https://github.com/ericclemmons/grunt-angular-templates
  4. *
  5. * Copyright (c) 2013 Eric Clemmons
  6. * Licensed under the MIT license.
  7. */
  8. 'use strict';
  9. module.exports = function(grunt) {
  10. grunt.initConfig({
  11. clean: {
  12. tests: 'tmp'
  13. },
  14. copy: {
  15. tmp: {
  16. files: [{
  17. expand: true,
  18. cwd: 'test/fixtures',
  19. src: ['usemin.html', 'usemin/*'],
  20. dest: 'tmp/'
  21. }]
  22. }
  23. },
  24. nodeunit: {
  25. tests: ['test/*.js']
  26. },
  27. watch: {
  28. tests: '<%= nodeunit.tests %>',
  29. tasks: 'default'
  30. },
  31. jshint: {
  32. all: ['Gruntfile.js', 'tasks/**/*.js', '<%= nodeunit.tests %>'],
  33. options: {
  34. jshintrc: '.jshintrc',
  35. }
  36. },
  37. concat: {
  38. custom_concat: {
  39. src: 'test/fixtures/one.html',
  40. dest: 'tmp/custom_concat_combined.js',
  41. options: {
  42. separator: '\n\n'
  43. }
  44. }
  45. },
  46. usemin: {
  47. html: 'tmp/usemin.html'
  48. },
  49. useminPrepare: {
  50. html: 'test/fixtures/usemin.html',
  51. options: {
  52. dest: 'tmp',
  53. staging: 'tmp'
  54. }
  55. },
  56. cssmin: {},
  57. // All supported examples should be here
  58. ngtemplates: {
  59. // Change `angular` namespace to something else
  60. custom_angular: {
  61. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  62. dest: 'tmp/custom_angular.js',
  63. options: {
  64. angular: 'myAngular'
  65. }
  66. },
  67. // Custom CommonJS bootstrapper
  68. custom_bootstrap: {
  69. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  70. dest: 'tmp/custom_bootstrap.js',
  71. options: {
  72. bootstrap: function(module, script) {
  73. return 'module.exports = function($templateCache) {\n' + script + '\n};\n';
  74. }
  75. }
  76. },
  77. // Append dest to existing concat target
  78. custom_concat: {
  79. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  80. dest: 'tmp/custom_concat.js',
  81. options: {
  82. concat: 'custom_concat'
  83. }
  84. },
  85. custom_usemin: {
  86. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  87. dest: 'tmp/custom_concat_usemin.js',
  88. options: {
  89. usemin: 'usemin/all.js'
  90. }
  91. },
  92. custom_usemin_not_found: {
  93. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  94. dest: 'tmp/custom_concat_usemin_not_found.js',
  95. options: {
  96. usemin: 'usemin/not_found.js'
  97. }
  98. },
  99. html5: {
  100. src: ['test/fixtures/html5.html'],
  101. dest: 'tmp/html5.js'
  102. },
  103. // Minify the HTML
  104. custom_htmlmin: {
  105. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  106. dest: 'tmp/custom_htmlmin.js',
  107. options: {
  108. htmlmin: {
  109. collapseBooleanAttributes: true,
  110. collapseWhitespace: true,
  111. removeAttributeQuotes: true,
  112. removeComments: true,
  113. removeEmptyAttributes: true,
  114. removeRedundantAttributes: true,
  115. removeScriptTypeAttributes: true,
  116. removeStyleLinkTypeAttributes: true
  117. }
  118. }
  119. },
  120. missing_htmlmin: {
  121. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  122. dest: 'tmp/missing_htmlmin.js',
  123. options: {
  124. htmlmin: null
  125. }
  126. },
  127. // Minify the HTML, but using another tasks' settings
  128. task_htmlmin: {
  129. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  130. dest: 'tmp/task_htmlmin.js',
  131. options: {
  132. htmlmin: '<%= ngtemplates.custom_htmlmin.options.htmlmin %>'
  133. }
  134. },
  135. // Default `module` option to the sub-task name (`default_module`)
  136. default_module: {
  137. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  138. dest: 'tmp/default_module.js'
  139. },
  140. // Customize angular module
  141. custom_module: {
  142. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  143. dest: 'tmp/custom_module.js',
  144. options: {
  145. module: 'customModule'
  146. }
  147. },
  148. // Customize angular module
  149. callback_module: {
  150. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  151. dest: 'tmp/callback_module.js',
  152. options: {
  153. module: function(url, options) {
  154. return url.split('/').join('.');
  155. },
  156. url: function(file) {
  157. return file.replace('.html', '');
  158. }
  159. }
  160. },
  161. // Customize template URL prefix
  162. custom_prefix: {
  163. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  164. dest: 'tmp/custom_prefix.js',
  165. options: {
  166. prefix: '/static'
  167. }
  168. },
  169. // Customize template source
  170. custom_source: {
  171. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  172. dest: 'tmp/custom_source.js',
  173. options: {
  174. source: function(source, url) {
  175. return "<!-- Template: " + url + " -->\n" + source;
  176. }
  177. }
  178. },
  179. // Module should be new & have [] defined
  180. standalone: {
  181. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  182. dest: 'tmp/standalone.js',
  183. options: {
  184. standalone: true
  185. }
  186. },
  187. // URLs should match path exactly
  188. full_url: {
  189. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  190. dest: 'tmp/full_url.js'
  191. },
  192. // URLs should match path, sans the `cwd`
  193. relative_url: {
  194. cwd: 'test/fixtures',
  195. src: ['one.html', 'two/**/*.html'],
  196. dest: 'tmp/relative_url.js'
  197. },
  198. // URLs should match path, sans the `cwd`
  199. relative_url_expand: {
  200. expand: true,
  201. cwd: 'test/fixtures',
  202. src: ['three/**/*.html'],
  203. dest: 'tmp',
  204. ext: '.js'
  205. },
  206. // Customize URLs to not have an extension
  207. custom_url: {
  208. src: ['test/fixtures/one.html', 'test/fixtures/two/**/*.html'],
  209. dest: 'tmp/custom_url.js',
  210. options: {
  211. url: function(url) {
  212. return url.replace('.html', '');
  213. }
  214. }
  215. },
  216. // Empty file
  217. empty_file: {
  218. src: 'test/fixtures/empty.html',
  219. dest: 'tmp/empty_file.js'
  220. },
  221. // undefined file
  222. undefined_file: {
  223. src: 'test/fixtures/undefined.html',
  224. dest: 'tmp/undefined_file.js'
  225. }
  226. }
  227. });
  228. // Load local tasks.
  229. grunt.loadTasks('tasks');
  230. grunt.loadNpmTasks('grunt-contrib-clean');
  231. grunt.loadNpmTasks('grunt-contrib-concat');
  232. grunt.loadNpmTasks('grunt-contrib-copy');
  233. grunt.loadNpmTasks('grunt-contrib-cssmin');
  234. grunt.loadNpmTasks('grunt-contrib-jshint');
  235. grunt.loadNpmTasks('grunt-contrib-nodeunit');
  236. grunt.loadNpmTasks('grunt-contrib-uglify');
  237. grunt.loadNpmTasks('grunt-usemin');
  238. grunt.registerTask('default', ['jshint', 'clean', 'copy', 'useminPrepare', 'ngtemplates', 'concat', 'uglify', 'cssmin', 'usemin', 'nodeunit']);
  239. };