No Description

Gruntfile.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. module.exports = function (grunt) {
  2. // From TWBS
  3. RegExp.quote = function (string) {
  4. return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
  5. };
  6. // Project configuration.
  7. grunt.initConfig({
  8. // Metadata.
  9. pkg: grunt.file.readJSON('package.json'),
  10. banner: '/*!\n' +
  11. ' * Bootstrap-select v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
  12. ' *\n' +
  13. ' * Copyright 2013-<%= grunt.template.today(\'yyyy\') %> bootstrap-select\n' +
  14. ' * Licensed under <%= pkg.license %> (https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE)\n' +
  15. ' */\n',
  16. // Task configuration.
  17. clean: {
  18. css: 'dist/css',
  19. js: 'dist/js',
  20. docs: 'docs/docs/dist'
  21. },
  22. jshint: {
  23. options: {
  24. jshintrc: 'js/.jshintrc'
  25. },
  26. gruntfile: {
  27. options: {
  28. 'node': true
  29. },
  30. src: 'Gruntfile.js'
  31. },
  32. main: {
  33. src: 'js/*.js'
  34. },
  35. i18n: {
  36. src: 'js/i18n/*.js'
  37. }
  38. },
  39. concat: {
  40. options: {
  41. stripBanners: true
  42. },
  43. main: {
  44. src: '<%= jshint.main.src %>',
  45. dest: 'dist/js/<%= pkg.name %>.js'
  46. },
  47. i18n: {
  48. expand: true,
  49. src: '<%= jshint.i18n.src %>',
  50. dest: 'dist/'
  51. }
  52. },
  53. umd: {
  54. main: {
  55. options: {
  56. deps: {
  57. 'default': ['jQuery'],
  58. amd: ['jquery'],
  59. cjs: ['jquery'],
  60. global: ['jQuery']
  61. }
  62. },
  63. src: '<%= concat.main.dest %>'
  64. },
  65. i18n: {
  66. options: {
  67. deps: {
  68. 'default': ['jQuery'],
  69. amd: ['jquery'],
  70. cjs: ['jquery'],
  71. global: ['jQuery']
  72. }
  73. },
  74. src: 'dist/<%= jshint.i18n.src %>',
  75. dest: '.'
  76. }
  77. },
  78. uglify: {
  79. options: {
  80. preserveComments: function(node, comment) {
  81. return /^!|@preserve|@license|@cc_on/i.test(comment.value);
  82. }
  83. },
  84. main: {
  85. src: '<%= concat.main.dest %>',
  86. dest: 'dist/js/<%= pkg.name %>.min.js',
  87. options: {
  88. sourceMap: true,
  89. sourceMapName: 'dist/js/<%= pkg.name %>.js.map'
  90. }
  91. },
  92. i18n: {
  93. expand: true,
  94. src: 'dist/<%= jshint.i18n.src %>',
  95. ext: '.min.js'
  96. }
  97. },
  98. less: {
  99. options: {
  100. strictMath: true,
  101. sourceMap: true,
  102. outputSourceFiles: true,
  103. sourceMapURL: '<%= pkg.name %>.css.map',
  104. sourceMapFilename: '<%= less.css.dest %>.map'
  105. },
  106. css: {
  107. src: 'less/bootstrap-select.less',
  108. dest: 'dist/css/<%= pkg.name %>.css'
  109. }
  110. },
  111. usebanner: {
  112. css: {
  113. options: {
  114. banner: '<%= banner %>'
  115. },
  116. src: '<%= less.css.dest %>'
  117. },
  118. js: {
  119. options: {
  120. banner: '<%= banner %>'
  121. },
  122. src: [
  123. '<%= concat.main.dest %>',
  124. '<%= uglify.main.dest %>',
  125. 'dist/<%= jshint.i18n.src %>',
  126. ]
  127. }
  128. },
  129. copy: {
  130. docs: {
  131. expand: true,
  132. cwd: 'dist/',
  133. src: [
  134. '**/*'
  135. ],
  136. dest: 'docs/docs/dist/'
  137. }
  138. },
  139. cssmin: {
  140. options: {
  141. compatibility: 'ie8',
  142. keepSpecialComments: '*',
  143. advanced: false
  144. },
  145. css: {
  146. src: '<%= less.css.dest %>',
  147. dest: 'dist/css/<%= pkg.name %>.min.css'
  148. }
  149. },
  150. csslint: {
  151. options: {
  152. 'adjoining-classes': false,
  153. 'box-sizing': false,
  154. 'box-model': false,
  155. 'compatible-vendor-prefixes': false,
  156. 'floats': false,
  157. 'font-sizes': false,
  158. 'gradients': false,
  159. 'important': false,
  160. 'known-properties': false,
  161. 'outline-none': false,
  162. 'qualified-headings': false,
  163. 'regex-selectors': false,
  164. 'shorthand': false,
  165. 'text-indent': false,
  166. 'unique-headings': false,
  167. 'universal-selector': false,
  168. 'unqualified-attributes': false,
  169. 'overqualified-elements': false
  170. },
  171. css: {
  172. src: '<%= less.css.dest %>'
  173. }
  174. },
  175. version: {
  176. js: {
  177. options: {
  178. prefix: 'Selectpicker.VERSION = \''
  179. },
  180. src: [
  181. 'js/<%= pkg.name %>.js'
  182. ],
  183. },
  184. cdn: {
  185. options: {
  186. prefix: 'ajax/libs/<%= pkg.name %>/'
  187. },
  188. src: [
  189. 'README.md',
  190. 'docs/docs/index.md'
  191. ],
  192. },
  193. nuget: {
  194. options: {
  195. prefix: '<version>'
  196. },
  197. src: [
  198. 'nuget/bootstrap-select.nuspec'
  199. ],
  200. },
  201. default: {
  202. options: {
  203. prefix: '[\'"]?version[\'"]?:[ "\']*'
  204. },
  205. src: [
  206. 'composer.json',
  207. 'docs/mkdocs.yml',
  208. 'package.json'
  209. ],
  210. }
  211. },
  212. autoprefixer: {
  213. options: {
  214. browsers: [
  215. 'Android 2.3',
  216. 'Android >= 4',
  217. 'Chrome >= 20',
  218. 'Firefox >= 24', // Firefox 24 is the latest ESR
  219. 'Explorer >= 8',
  220. 'iOS >= 6',
  221. 'Opera >= 12',
  222. 'Safari >= 6'
  223. ]
  224. },
  225. css: {
  226. options: {
  227. map: true
  228. },
  229. src: '<%= less.css.dest %>'
  230. }
  231. },
  232. compress: {
  233. zip: {
  234. options: {
  235. archive: 'bootstrap-select-<%= pkg.version %>.zip',
  236. mode: 'zip'
  237. },
  238. files: [
  239. {
  240. expand: true,
  241. cwd: 'dist/',
  242. src: '**',
  243. dest: 'bootstrap-select-<%= pkg.version %>/'
  244. }, {
  245. src: ['bower.json', 'composer.json', 'package.json'],
  246. dest: 'bootstrap-select-<%= pkg.version %>/'
  247. }
  248. ]
  249. }
  250. },
  251. watch: {
  252. gruntfile: {
  253. files: '<%= jshint.gruntfile.src %>',
  254. tasks: 'jshint:gruntfile'
  255. },
  256. js: {
  257. files: ['<%= jshint.main.src %>', '<%= jshint.i18n.src %>'],
  258. tasks: 'build-js'
  259. },
  260. less: {
  261. files: 'less/*.less',
  262. tasks: 'build-css'
  263. }
  264. }
  265. });
  266. // These plugins provide necessary tasks.
  267. require('load-grunt-tasks')(grunt, {
  268. scope: 'devDependencies'
  269. });
  270. // Version numbering task.
  271. // to update version number, use grunt version::x.y.z
  272. // CSS distribution
  273. grunt.registerTask('build-css', ['clean:css', 'less', 'autoprefixer', 'usebanner:css', 'cssmin']);
  274. // JS distribution
  275. grunt.registerTask('build-js', ['clean:js', 'concat', 'umd', 'usebanner:js', 'uglify']);
  276. // Copy dist to docs
  277. grunt.registerTask('docs', ['clean:docs', 'copy:docs']);
  278. // Development watch
  279. grunt.registerTask('dev-watch', ['build-css', 'build-js', 'watch']);
  280. // Full distribution
  281. grunt.registerTask('dist', ['build-css', 'build-js', 'compress']);
  282. // Default task.
  283. grunt.registerTask('default', ['build-css', 'build-js']);
  284. };