Gruntfile.js 4.5 KB

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