Gruntfile.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. output: {
  115. comments: 'some'
  116. },
  117. },
  118. production: {
  119. files: {
  120. 'dist/js/adminlte.min.js': ['dist/js/adminlte.js']
  121. }
  122. }
  123. },
  124. // Concatenate JS Files
  125. concat: {
  126. options: {
  127. separator: '\n\n',
  128. banner : '/*! AdminLTE app.js\n'
  129. + '* ================\n'
  130. + '* Main JS application file for AdminLTE v2. This file\n'
  131. + '* should be included in all pages. It controls some layout\n'
  132. + '* options and implements exclusive AdminLTE plugins.\n'
  133. + '*\n'
  134. + '* @author Colorlib\n'
  135. + '* @support <https://github.com/ColorlibHQ/AdminLTE/issues>\n'
  136. + '* @version <%= pkg.version %>\n'
  137. + '* @repository <%= pkg.repository.url %>\n'
  138. + '* @license MIT <http://opensource.org/licenses/MIT>\n'
  139. + '*/\n\n'
  140. + '// Make sure jQuery has been loaded\n'
  141. + 'if (typeof jQuery === \'undefined\') {\n'
  142. + 'throw new Error(\'AdminLTE requires jQuery\')\n'
  143. + '}\n\n'
  144. },
  145. dist : {
  146. src : [
  147. 'build/js/BoxRefresh.js',
  148. 'build/js/BoxWidget.js',
  149. 'build/js/ControlSidebar.js',
  150. 'build/js/DirectChat.js',
  151. 'build/js/PushMenu.js',
  152. 'build/js/TodoList.js',
  153. 'build/js/Tree.js',
  154. 'build/js/Layout.js',
  155. ],
  156. dest: 'dist/js/adminlte.js'
  157. }
  158. },
  159. // Replace image paths in AdminLTE without plugins
  160. replace: {
  161. withoutPlugins : {
  162. src : ['dist/css/alt/AdminLTE-without-plugins.css'],
  163. dest : 'dist/css/alt/AdminLTE-without-plugins.css',
  164. replacements: [
  165. {
  166. from: '../img',
  167. to : '../../img'
  168. }
  169. ]
  170. },
  171. withoutPluginsMin: {
  172. src : ['dist/css/alt/AdminLTE-without-plugins.min.css'],
  173. dest : 'dist/css/alt/AdminLTE-without-plugins.min.css',
  174. replacements: [
  175. {
  176. from: '../img',
  177. to : '../../img'
  178. }
  179. ]
  180. }
  181. },
  182. // Build the documentation files
  183. includes: {
  184. build: {
  185. src : ['*.html'], // Source files
  186. dest : 'documentation/', // Destination directory
  187. flatten: true,
  188. cwd : 'documentation/build',
  189. options: {
  190. silent : true,
  191. includePath: 'documentation/build/include'
  192. }
  193. }
  194. },
  195. // Optimize images
  196. image: {
  197. dynamic: {
  198. files: [
  199. {
  200. expand: true,
  201. cwd : 'build/img/',
  202. src : ['**/*.{png,jpg,gif,svg,jpeg}'],
  203. dest : 'dist/img/'
  204. }
  205. ]
  206. }
  207. },
  208. // Validate JS code
  209. jshint: {
  210. options: {
  211. jshintrc: 'build/js/.jshintrc'
  212. },
  213. grunt : {
  214. options: {
  215. jshintrc: 'build/grunt/.jshintrc'
  216. },
  217. src : 'Gruntfile.js'
  218. },
  219. core : {
  220. src: 'build/js/*.js'
  221. },
  222. demo : {
  223. src: 'dist/js/demo.js'
  224. },
  225. pages : {
  226. src: 'dist/js/pages/*.js'
  227. }
  228. },
  229. jscs: {
  230. options: {
  231. config: 'build/js/.jscsrc'
  232. },
  233. core : {
  234. src: '<%= jshint.core.src %>'
  235. },
  236. pages : {
  237. src: '<%= jshint.pages.src %>'
  238. }
  239. },
  240. // Validate CSS files
  241. csslint: {
  242. options: {
  243. csslintrc: 'build/less/.csslintrc'
  244. },
  245. dist : [
  246. 'dist/css/AdminLTE.css'
  247. ]
  248. },
  249. // Validate Bootstrap HTML
  250. bootlint: {
  251. options: {
  252. relaxerror: ['W005']
  253. },
  254. files : ['pages/**/*.html', '*.html']
  255. },
  256. // Delete images in build directory
  257. // After compressing the images in the build/img dir, there is no need
  258. // for them
  259. clean: {
  260. build: ['build/img/*']
  261. }
  262. });
  263. // Load all grunt tasks
  264. // LESS Compiler
  265. grunt.loadNpmTasks('grunt-contrib-less');
  266. // Watch File Changes
  267. grunt.loadNpmTasks('grunt-contrib-watch');
  268. // Compress JS Files
  269. grunt.loadNpmTasks('grunt-contrib-uglify');
  270. // Include Files Within HTML
  271. grunt.loadNpmTasks('grunt-includes');
  272. // Optimize images
  273. grunt.loadNpmTasks('grunt-image');
  274. // Validate JS code
  275. grunt.loadNpmTasks('grunt-contrib-jshint');
  276. grunt.loadNpmTasks('grunt-jscs');
  277. // Delete not needed files
  278. grunt.loadNpmTasks('grunt-contrib-clean');
  279. // Lint CSS
  280. grunt.loadNpmTasks('grunt-contrib-csslint');
  281. // Lint Bootstrap
  282. grunt.loadNpmTasks('grunt-bootlint');
  283. // Concatenate JS files
  284. grunt.loadNpmTasks('grunt-contrib-concat');
  285. // Notify
  286. grunt.loadNpmTasks('grunt-notify');
  287. // Replace
  288. grunt.loadNpmTasks('grunt-text-replace');
  289. // Linting task
  290. grunt.registerTask('lint', ['jshint', 'csslint', 'bootlint']);
  291. // JS task
  292. grunt.registerTask('js', ['concat', 'uglify']);
  293. // CSS Task
  294. grunt.registerTask('css', ['less:development', 'less:production', 'replace']);
  295. // The default task (running 'grunt' in console) is 'watch'
  296. grunt.registerTask('default', ['watch']);
  297. };