Gruntfile.js 4.2 KB

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