Gruntfile.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // AdminLTE Gruntfile
  2. module.exports = function (grunt) { // jshint ignore:line
  3. 'use strict';
  4. grunt.initConfig({
  5. pkg : grunt.file.readJSON('package.json'),
  6. watch : {
  7. less : {
  8. // Compiles less files upon saving
  9. files: ['build/less/*.less'],
  10. tasks: ['less:development', 'less:production', 'replace', 'notify:less']
  11. },
  12. js : {
  13. // Compile js files upon saving
  14. files: ['build/js/*.js'],
  15. tasks: ['js', 'notify:js']
  16. },
  17. skins: {
  18. // Compile any skin less files upon saving
  19. files: ['build/less/skins/*.less'],
  20. tasks: ['less:skins', 'less:minifiedSkins', 'notify:less']
  21. }
  22. },
  23. // Notify end of tasks
  24. notify: {
  25. less: {
  26. options: {
  27. title : 'AdminLTE',
  28. message: 'LESS finished running'
  29. }
  30. },
  31. js : {
  32. options: {
  33. title : 'AdminLTE',
  34. message: 'JS bundler finished running'
  35. }
  36. }
  37. },
  38. // 'less'-task configuration
  39. // This task will compile all less files upon saving to create both AdminLTE.css and AdminLTE.min.css
  40. less : {
  41. // Development not compressed
  42. development : {
  43. files: {
  44. // compilation.css : source.less
  45. 'dist/css/AdminLTE.css' : 'build/less/AdminLTE.less',
  46. // AdminLTE without plugins
  47. 'dist/css/alt/AdminLTE-without-plugins.css' : 'build/less/AdminLTE-without-plugins.less',
  48. // Separate plugins
  49. 'dist/css/alt/AdminLTE-select2.css' : 'build/less/select2.less',
  50. 'dist/css/alt/AdminLTE-fullcalendar.css' : 'build/less/fullcalendar.less',
  51. 'dist/css/alt/AdminLTE-bootstrap-social.css': 'build/less/bootstrap-social.less'
  52. }
  53. },
  54. // Production compressed version
  55. production : {
  56. options: {
  57. compress: true
  58. },
  59. files : {
  60. // compilation.css : source.less
  61. 'dist/css/AdminLTE.min.css' : 'build/less/AdminLTE.less',
  62. // AdminLTE without plugins
  63. 'dist/css/alt/AdminLTE-without-plugins.min.css' : 'build/less/AdminLTE-without-plugins.less',
  64. // Separate plugins
  65. 'dist/css/alt/AdminLTE-select2.min.css' : 'build/less/select2.less',
  66. 'dist/css/alt/AdminLTE-fullcalendar.min.css' : 'build/less/fullcalendar.less',
  67. 'dist/css/alt/AdminLTE-bootstrap-social.min.css': 'build/less/bootstrap-social.less'
  68. }
  69. },
  70. // Non minified skin files
  71. skins : {
  72. files: {
  73. 'dist/css/skins/skin-blue.css' : 'build/less/skins/skin-blue.less',
  74. 'dist/css/skins/skin-black.css' : 'build/less/skins/skin-black.less',
  75. 'dist/css/skins/skin-yellow.css' : 'build/less/skins/skin-yellow.less',
  76. 'dist/css/skins/skin-green.css' : 'build/less/skins/skin-green.less',
  77. 'dist/css/skins/skin-red.css' : 'build/less/skins/skin-red.less',
  78. 'dist/css/skins/skin-purple.css' : 'build/less/skins/skin-purple.less',
  79. 'dist/css/skins/skin-blue-light.css' : 'build/less/skins/skin-blue-light.less',
  80. 'dist/css/skins/skin-black-light.css' : 'build/less/skins/skin-black-light.less',
  81. 'dist/css/skins/skin-yellow-light.css': 'build/less/skins/skin-yellow-light.less',
  82. 'dist/css/skins/skin-green-light.css' : 'build/less/skins/skin-green-light.less',
  83. 'dist/css/skins/skin-red-light.css' : 'build/less/skins/skin-red-light.less',
  84. 'dist/css/skins/skin-purple-light.css': 'build/less/skins/skin-purple-light.less',
  85. 'dist/css/skins/_all-skins.css' : 'build/less/skins/_all-skins.less'
  86. }
  87. },
  88. // Skins minified
  89. minifiedSkins: {
  90. options: {
  91. compress: true
  92. },
  93. files : {
  94. 'dist/css/skins/skin-blue.min.css' : 'build/less/skins/skin-blue.less',
  95. 'dist/css/skins/skin-black.min.css' : 'build/less/skins/skin-black.less',
  96. 'dist/css/skins/skin-yellow.min.css' : 'build/less/skins/skin-yellow.less',
  97. 'dist/css/skins/skin-green.min.css' : 'build/less/skins/skin-green.less',
  98. 'dist/css/skins/skin-red.min.css' : 'build/less/skins/skin-red.less',
  99. 'dist/css/skins/skin-purple.min.css' : 'build/less/skins/skin-purple.less',
  100. 'dist/css/skins/skin-blue-light.min.css' : 'build/less/skins/skin-blue-light.less',
  101. 'dist/css/skins/skin-black-light.min.css' : 'build/less/skins/skin-black-light.less',
  102. 'dist/css/skins/skin-yellow-light.min.css': 'build/less/skins/skin-yellow-light.less',
  103. 'dist/css/skins/skin-green-light.min.css' : 'build/less/skins/skin-green-light.less',
  104. 'dist/css/skins/skin-red-light.min.css' : 'build/less/skins/skin-red-light.less',
  105. 'dist/css/skins/skin-purple-light.min.css': 'build/less/skins/skin-purple-light.less',
  106. 'dist/css/skins/_all-skins.min.css' : 'build/less/skins/_all-skins.less'
  107. }
  108. }
  109. },
  110. // Uglify task info. Compress the js files.
  111. uglify: {
  112. options : {
  113. mangle : true,
  114. preserveComments: 'some'
  115. },
  116. production: {
  117. files: {
  118. 'dist/js/adminlte.min.js': ['dist/js/adminlte.js']
  119. }
  120. }
  121. },
  122. // Concatenate JS Files
  123. concat: {
  124. options: {
  125. separator: '\n\n',
  126. banner : '/*! AdminLTE app.js\n'
  127. + '* ================\n'
  128. + '* Main JS application file for AdminLTE v2. This file\n'
  129. + '* should be included in all pages. It controls some layout\n'
  130. + '* options and implements exclusive AdminLTE plugins.\n'
  131. + '*\n'
  132. + '* @author Colorlib\n'
  133. + '* @support <https://github.com/ColorlibHQ/AdminLTE/issues>\n'
  134. + '* @version <%= pkg.version %>\n'
  135. + '* @repository <%= pkg.repository.url %>\n'
  136. + '* @license MIT <http://opensource.org/licenses/MIT>\n'
  137. + '*/\n\n'
  138. + '// Make sure jQuery has been loaded\n'
  139. + 'if (typeof jQuery === \'undefined\') {\n'
  140. + 'throw new Error(\'AdminLTE requires jQuery\')\n'
  141. + '}\n\n'
  142. },
  143. dist : {
  144. src : [
  145. 'build/js/BoxRefresh.js',
  146. 'build/js/BoxWidget.js',
  147. 'build/js/ControlSidebar.js',
  148. 'build/js/DirectChat.js',
  149. 'build/js/PushMenu.js',
  150. 'build/js/TodoList.js',
  151. 'build/js/Tree.js',
  152. 'build/js/Layout.js',
  153. ],
  154. dest: 'dist/js/adminlte.js'
  155. }
  156. },
  157. // Replace image paths in AdminLTE without plugins
  158. replace: {
  159. withoutPlugins : {
  160. src : ['dist/css/alt/AdminLTE-without-plugins.css'],
  161. dest : 'dist/css/alt/AdminLTE-without-plugins.css',
  162. replacements: [
  163. {
  164. from: '../img',
  165. to : '../../img'
  166. }
  167. ]
  168. },
  169. withoutPluginsMin: {
  170. src : ['dist/css/alt/AdminLTE-without-plugins.min.css'],
  171. dest : 'dist/css/alt/AdminLTE-without-plugins.min.css',
  172. replacements: [
  173. {
  174. from: '../img',
  175. to : '../../img'
  176. }
  177. ]
  178. }
  179. },
  180. // Build the documentation files
  181. includes: {
  182. build: {
  183. src : ['*.html'], // Source files
  184. dest : 'documentation/', // Destination directory
  185. flatten: true,
  186. cwd : 'documentation/build',
  187. options: {
  188. silent : true,
  189. includePath: 'documentation/build/include'
  190. }
  191. }
  192. },
  193. // Optimize images
  194. image: {
  195. dynamic: {
  196. files: [
  197. {
  198. expand: true,
  199. cwd : 'build/img/',
  200. src : ['**/*.{png,jpg,gif,svg,jpeg}'],
  201. dest : 'dist/img/'
  202. }
  203. ]
  204. }
  205. },
  206. // Validate JS code
  207. jshint: {
  208. options: {
  209. jshintrc: 'build/js/.jshintrc'
  210. },
  211. grunt : {
  212. options: {
  213. jshintrc: 'build/grunt/.jshintrc'
  214. },
  215. src : 'Gruntfile.js'
  216. },
  217. core : {
  218. src: 'build/js/*.js'
  219. },
  220. demo : {
  221. src: 'dist/js/demo.js'
  222. },
  223. pages : {
  224. src: 'dist/js/pages/*.js'
  225. }
  226. },
  227. jscs: {
  228. options: {
  229. config: 'build/js/.jscsrc'
  230. },
  231. core : {
  232. src: '<%= jshint.core.src %>'
  233. },
  234. pages : {
  235. src: '<%= jshint.pages.src %>'
  236. }
  237. },
  238. // Validate CSS files
  239. csslint: {
  240. options: {
  241. csslintrc: 'build/less/.csslintrc'
  242. },
  243. dist : [
  244. 'dist/css/AdminLTE.css'
  245. ]
  246. },
  247. // Validate Bootstrap HTML
  248. bootlint: {
  249. options: {
  250. relaxerror: ['W005']
  251. },
  252. files : ['pages/**/*.html', '*.html']
  253. },
  254. // Delete images in build directory
  255. // After compressing the images in the build/img dir, there is no need
  256. // for them
  257. clean: {
  258. build: ['build/img/*']
  259. }
  260. });
  261. // Load all grunt tasks
  262. // LESS Compiler
  263. grunt.loadNpmTasks('grunt-contrib-less');
  264. // Watch File Changes
  265. grunt.loadNpmTasks('grunt-contrib-watch');
  266. // Compress JS Files
  267. grunt.loadNpmTasks('grunt-contrib-uglify');
  268. // Include Files Within HTML
  269. grunt.loadNpmTasks('grunt-includes');
  270. // Optimize images
  271. grunt.loadNpmTasks('grunt-image');
  272. // Validate JS code
  273. grunt.loadNpmTasks('grunt-contrib-jshint');
  274. grunt.loadNpmTasks('grunt-jscs');
  275. // Delete not needed files
  276. grunt.loadNpmTasks('grunt-contrib-clean');
  277. // Lint CSS
  278. grunt.loadNpmTasks('grunt-contrib-csslint');
  279. // Lint Bootstrap
  280. grunt.loadNpmTasks('grunt-bootlint');
  281. // Concatenate JS files
  282. grunt.loadNpmTasks('grunt-contrib-concat');
  283. // Notify
  284. grunt.loadNpmTasks('grunt-notify');
  285. // Replace
  286. grunt.loadNpmTasks('grunt-text-replace');
  287. // Linting task
  288. grunt.registerTask('lint', ['jshint', 'csslint', 'bootlint']);
  289. // JS task
  290. grunt.registerTask('js', ['concat', 'uglify']);
  291. // CSS Task
  292. grunt.registerTask('css', ['less:development', 'less:production', 'replace']);
  293. // The default task (running 'grunt' in console) is 'watch'
  294. grunt.registerTask('default', ['watch']);
  295. };