Gruntfile.js 5.0 KB

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