Gruntfile.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. module.exports = function (grunt) {
  2. // Full list of files that must be included by RequireJS
  3. includes = [
  4. 'jquery.select2'
  5. ];
  6. amdIncludes = [
  7. 'almond'
  8. ];
  9. fullIncludes = [
  10. 'jquery',
  11. 'select2/compat/matcher'
  12. ].concat(includes);
  13. var i18nModules = [];
  14. var i18nPaths = {};
  15. var i18nFiles = grunt.file.expand({
  16. cwd: 'src/js'
  17. }, 'select2/i18n/*.js');
  18. for (var i = 0; i < i18nFiles.length; i++) {
  19. var file = i18nFiles[i];
  20. var name = file.split('.')[0];
  21. i18nModules.push({
  22. name: name
  23. });
  24. i18nPaths[name] = '../../' + name;
  25. }
  26. grunt.initConfig({
  27. clean: {
  28. docs: ['docs/_site']
  29. },
  30. uglify: {
  31. 'dist': {
  32. src: 'dist/js/select2.js',
  33. dest: 'dist/js/select2.min.js'
  34. },
  35. 'dist.full': {
  36. src: 'dist/js/select2.full.js',
  37. dest: 'dist/js/select2.full.min.js'
  38. }
  39. },
  40. qunit: {
  41. all: [
  42. 'tests/**/*.html'
  43. ]
  44. },
  45. 'gh-pages': {
  46. options: {
  47. base: 'docs',
  48. clone: 'node_modules/grunt-gh-pages/repo',
  49. message: 'Updated docs with master',
  50. push: false,
  51. repo: '[email protected]:kevin-brown/select2.git'
  52. },
  53. src: '**'
  54. },
  55. jekyll: {
  56. options: {
  57. src: 'docs',
  58. dest: 'docs/_site'
  59. },
  60. build: {
  61. d: null
  62. },
  63. serve: {
  64. options: {
  65. serve: true,
  66. watch: true
  67. }
  68. }
  69. },
  70. jshint: {
  71. options: {
  72. jshintrc: true
  73. },
  74. code: {
  75. src: ['src/js/**/*.js']
  76. },
  77. tests: {
  78. src: ['tests/**/*.js']
  79. }
  80. },
  81. sass: {
  82. dist: {
  83. options: {
  84. outputStyle: 'compressed'
  85. },
  86. files: {
  87. 'dist/css/select2.min.css': [
  88. 'src/scss/core.scss',
  89. 'src/scss/theme/default/layout.css'
  90. ]
  91. }
  92. },
  93. dev: {
  94. options: {
  95. outputStyle: 'nested'
  96. },
  97. files: {
  98. 'dist/css/select2.css': [
  99. 'src/scss/core.scss',
  100. 'src/scss/theme/default/layout.css'
  101. ]
  102. }
  103. }
  104. },
  105. requirejs: {
  106. 'dist': {
  107. options: {
  108. baseUrl: 'src/js',
  109. optimize: 'none',
  110. name: 'select2/core',
  111. out: 'dist/js/select2.js',
  112. include: amdIncludes.concat(includes),
  113. paths: {
  114. almond: '../../vendor/almond-0.2.9',
  115. jquery: 'jquery.shim'
  116. },
  117. wrap: grunt.file.readJSON('src/js/banner.json')
  118. }
  119. },
  120. 'dist.full': {
  121. options: {
  122. baseUrl: 'src/js',
  123. optimize: 'none',
  124. name: 'select2/core',
  125. out: 'dist/js/select2.full.js',
  126. include: amdIncludes.concat(fullIncludes),
  127. paths: {
  128. almond: '../../vendor/almond-0.2.9',
  129. jquery: '../../vendor/jquery-2.1.0'
  130. },
  131. wrap: grunt.file.readJSON('src/js/banner.json')
  132. }
  133. },
  134. 'amd': {
  135. options: {
  136. baseUrl: 'src/js',
  137. optimize: 'none',
  138. name: 'select2/core',
  139. out: 'dist/js/select2.amd.js',
  140. include: includes,
  141. paths: {
  142. jquery: 'empty:'
  143. },
  144. wrap: grunt.file.readJSON('src/js/banner.json')
  145. }
  146. },
  147. 'amd.full': {
  148. options: {
  149. baseUrl: 'src/js',
  150. optimize: 'none',
  151. name: 'select2/core',
  152. out: 'dist/js/select2.amd.full.js',
  153. include: fullIncludes,
  154. paths: {
  155. jquery: 'empty:'
  156. },
  157. wrap: grunt.file.readJSON('src/js/banner.json')
  158. }
  159. },
  160. 'i18n': {
  161. options: {
  162. baseUrl: 'src/js/select2/i18n',
  163. dir: 'dist/js/i18n',
  164. paths: i18nPaths,
  165. modules: i18nModules,
  166. wrap: grunt.file.readJSON('src/js/banner.json')
  167. }
  168. }
  169. },
  170. watch: {
  171. js: {
  172. files: [
  173. 'src/js/select2/**/*.js',
  174. 'tests/**/*.js'
  175. ],
  176. tasks: [
  177. 'compile',
  178. 'test',
  179. 'minify'
  180. ]
  181. },
  182. css: {
  183. files: [
  184. 'src/scss/**/*.scss'
  185. ],
  186. tasks: [
  187. 'compile',
  188. 'minify'
  189. ]
  190. }
  191. }
  192. });
  193. grunt.loadNpmTasks('grunt-contrib-clean');
  194. grunt.loadNpmTasks('grunt-contrib-concat');
  195. grunt.loadNpmTasks('grunt-contrib-jshint');
  196. grunt.loadNpmTasks('grunt-contrib-qunit');
  197. grunt.loadNpmTasks('grunt-contrib-requirejs');
  198. grunt.loadNpmTasks('grunt-contrib-uglify');
  199. grunt.loadNpmTasks('grunt-contrib-watch');
  200. grunt.loadNpmTasks('grunt-gh-pages');
  201. grunt.loadNpmTasks('grunt-jekyll');
  202. grunt.loadNpmTasks('grunt-sass');
  203. grunt.registerTask('default', ['compile', 'test', 'minify']);
  204. grunt.registerTask('compile', ['requirejs', 'sass:dev']);
  205. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  206. grunt.registerTask('test', ['qunit', 'jshint']);
  207. grunt.registerTask('docs', ['jekyll:serve']);
  208. grunt.registerTask('release', ['default', 'clean:docs', 'gh-pages']);
  209. };