Gruntfile.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. uglify: {
  28. 'dist': {
  29. src: 'dist/js/select2.js',
  30. dest: 'dist/js/select2.min.js'
  31. },
  32. 'dist.full': {
  33. src: 'dist/js/select2.full.js',
  34. dest: 'dist/js/select2.full.min.js'
  35. }
  36. },
  37. qunit: {
  38. all: [
  39. 'tests/**/*.html'
  40. ]
  41. },
  42. jekyll: {
  43. options: {
  44. src: 'docs',
  45. dest: 'docs/_site'
  46. },
  47. build: {
  48. d: null
  49. },
  50. serve: {
  51. options: {
  52. serve: true,
  53. watch: true
  54. }
  55. }
  56. },
  57. jshint: {
  58. options: {
  59. jshintrc: true
  60. },
  61. code: {
  62. src: ['src/js/**/*.js']
  63. },
  64. tests: {
  65. src: ['tests/**/*.js']
  66. }
  67. },
  68. sass: {
  69. dist: {
  70. options: {
  71. outputStyle: 'compressed'
  72. },
  73. files: {
  74. 'dist/css/select2.min.css': [
  75. 'src/scss/core.scss',
  76. 'src/scss/theme/default/layout.css'
  77. ]
  78. }
  79. },
  80. dev: {
  81. options: {
  82. outputStyle: 'nested'
  83. },
  84. files: {
  85. 'dist/css/select2.css': [
  86. 'src/scss/core.scss',
  87. 'src/scss/theme/default/layout.css'
  88. ]
  89. }
  90. }
  91. },
  92. requirejs: {
  93. 'dist': {
  94. options: {
  95. baseUrl: 'src/js',
  96. optimize: 'none',
  97. name: 'select2/core',
  98. out: 'dist/js/select2.js',
  99. include: amdIncludes.concat(includes),
  100. paths: {
  101. almond: '../../vendor/almond-0.2.9',
  102. jquery: 'jquery.shim'
  103. },
  104. wrap: grunt.file.readJSON('src/js/banner.json')
  105. }
  106. },
  107. 'dist.full': {
  108. options: {
  109. baseUrl: 'src/js',
  110. optimize: 'none',
  111. name: 'select2/core',
  112. out: 'dist/js/select2.full.js',
  113. include: amdIncludes.concat(fullIncludes),
  114. paths: {
  115. almond: '../../vendor/almond-0.2.9',
  116. jquery: '../../vendor/jquery-2.1.0'
  117. },
  118. wrap: grunt.file.readJSON('src/js/banner.json')
  119. }
  120. },
  121. 'amd': {
  122. options: {
  123. baseUrl: 'src/js',
  124. optimize: 'none',
  125. name: 'select2/core',
  126. out: 'dist/js/select2.amd.js',
  127. include: includes,
  128. paths: {
  129. jquery: 'empty:'
  130. },
  131. wrap: grunt.file.readJSON('src/js/banner.json')
  132. }
  133. },
  134. 'amd.full': {
  135. options: {
  136. baseUrl: 'src/js',
  137. optimize: 'none',
  138. name: 'select2/core',
  139. out: 'dist/js/select2.amd.full.js',
  140. include: fullIncludes,
  141. paths: {
  142. jquery: 'empty:'
  143. },
  144. wrap: grunt.file.readJSON('src/js/banner.json')
  145. }
  146. },
  147. 'i18n': {
  148. options: {
  149. baseUrl: 'src/js/select2/i18n',
  150. dir: 'dist/js/i18n',
  151. paths: i18nPaths,
  152. modules: i18nModules,
  153. wrap: grunt.file.readJSON('src/js/banner.json')
  154. }
  155. }
  156. },
  157. watch: {
  158. js: {
  159. files: [
  160. 'src/js/select2/**/*.js',
  161. 'tests/**/*.js'
  162. ],
  163. tasks: [
  164. 'compile',
  165. 'test',
  166. 'minify'
  167. ]
  168. },
  169. css: {
  170. files: [
  171. 'src/scss/**/*.scss'
  172. ],
  173. tasks: [
  174. 'compile',
  175. 'minify'
  176. ]
  177. }
  178. }
  179. });
  180. grunt.loadNpmTasks('grunt-contrib-concat');
  181. grunt.loadNpmTasks('grunt-contrib-jshint');
  182. grunt.loadNpmTasks('grunt-contrib-qunit');
  183. grunt.loadNpmTasks('grunt-contrib-requirejs');
  184. grunt.loadNpmTasks('grunt-contrib-uglify');
  185. grunt.loadNpmTasks('grunt-contrib-watch');
  186. grunt.loadNpmTasks('grunt-jekyll');
  187. grunt.loadNpmTasks('grunt-sass');
  188. grunt.registerTask('default', ['compile', 'test', 'minify']);
  189. grunt.registerTask('compile', ['requirejs', 'sass:dev']);
  190. grunt.registerTask('minify', ['uglify', 'sass:dist']);
  191. grunt.registerTask('test', ['qunit', 'jshint']);
  192. grunt.registerTask('docs', ['jekyll:serve']);
  193. grunt.registerTask('release', ['default', 'jekyll:build']);
  194. };