Gruntfile.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // AdminLTE Gruntfile
  2. module.exports = function (grunt) {
  3. 'use strict'
  4. grunt.initConfig({
  5. // Metadata.
  6. pkg: grunt.file.readJSON('package.json'),
  7. banner: '/*!\n' +
  8. ' * AdminLTE v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
  9. ' * Copyright 2014-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
  10. ' * Project website Almsaeed Studio (https://almsaeedstudio.com)\n' +
  11. ' * Licensed under MIT (https://github.com/almasaeed2010/AdminLTE/blob/master/LICENSE)\n' +
  12. ' */\n',
  13. // Watch files for changes and invoke appropriate compiler
  14. watch: {
  15. sass: {
  16. files: ['build/scss/*.scss', 'build/scss/skins/*.scss'],
  17. tasks: ['sass']
  18. },
  19. es6: {
  20. files: ['build/js/src/*.js'],
  21. tasks: ['babel']
  22. },
  23. js: {
  24. files: ['dist/js/AdminLTE.js', 'dist/js/app.js'],
  25. tasks: ['uglify']
  26. }
  27. },
  28. // SASS compiler
  29. sass: {
  30. development: {
  31. options: {
  32. style: 'expanded'
  33. },
  34. files: {
  35. 'dist/css/AdminLTE.css': 'build/scss/AdminLTE.scss'
  36. }
  37. },
  38. production: {
  39. options: {
  40. style: 'compressed'
  41. },
  42. files: {
  43. 'dist/css/adminlte.min.css': 'build/scss/AdminLTE.scss'
  44. }
  45. }
  46. },
  47. // Compress the js files.
  48. uglify: {
  49. options: {
  50. mangle: true,
  51. preserveComments: 'some'
  52. },
  53. target: {
  54. files: {
  55. 'dist/js/adminlte.min.js': ['dist/js/adminlte.js'],
  56. 'dist/js/app.min.js': ['dist/js/app.js']
  57. }
  58. }
  59. },
  60. // Compile ES6
  61. babel: {
  62. options: {
  63. sourceMap: true,
  64. presets: ['es2015']
  65. },
  66. dist: {
  67. files: {
  68. 'build/js/dist/Treeview.js': 'build/js/src/Treeview.js',
  69. 'build/js/dist/PushMenu.js': 'build/js/src/PushMenu.js',
  70. 'build/js/dist/Widget.js': 'build/js/src/Widget.js'
  71. }
  72. }
  73. },
  74. // Concat compiled JS files
  75. concat: {
  76. options: {
  77. stripBanners: true,
  78. banner: '<%= banner %>'
  79. },
  80. adminlte: {
  81. src: [
  82. 'build/js/dist/Treeview.js',
  83. 'build/js/dist/PushMenu.js',
  84. 'build/js/dist/Widget.js'
  85. ],
  86. dest: 'dist/js/adminlte.js'
  87. }
  88. },
  89. // Build the documentation files
  90. includes: {
  91. build: {
  92. src: ['*.html'], // Source files
  93. dest: 'documentation/', // Destination directory
  94. flatten: true,
  95. cwd: 'documentation/build',
  96. options: {
  97. silent: true,
  98. includePath: 'documentation/build/include'
  99. }
  100. }
  101. },
  102. // Optimize images
  103. image: {
  104. dynamic: {
  105. files: [
  106. {
  107. expand: true,
  108. cwd: 'build/img/',
  109. src: ['**/*.{png,jpg,gif,svg,jpeg}'],
  110. dest: 'dist/img/'
  111. }
  112. ]
  113. }
  114. },
  115. eslint: {
  116. options: {
  117. configFile: 'build/js/.eslintrc'
  118. },
  119. target: 'build/js/src/*.js'
  120. },
  121. // Lint JS code
  122. jscs: {
  123. options: {
  124. config: 'build/js/.jscsrc'
  125. },
  126. grunt: {
  127. src: ['Gruntfile.js']
  128. },
  129. core: {
  130. src: 'js/src/*.js'
  131. }
  132. /*app: {
  133. src: 'dist/js/app.js'
  134. }*/
  135. },
  136. // Validate CSS files
  137. csslint: {
  138. options: {
  139. csslintrc: 'build/scss/.csslintrc'
  140. },
  141. dist: [
  142. 'dist/css/AdminLTE.css'
  143. ]
  144. },
  145. // Validate Bootstrap HTML
  146. bootlint: {
  147. options: {
  148. relaxerror: ['W005']
  149. },
  150. files: ['pages/**/*.html', '*.html']
  151. },
  152. // Delete images in build directory
  153. // After compressing the images in the build/img dir, there is no need
  154. // for them
  155. clean: {
  156. build: ['build/img/*']
  157. }
  158. })
  159. // Load all grunt tasks
  160. // SASS compiler
  161. grunt.loadNpmTasks('grunt-sass')
  162. // Watch File Changes
  163. grunt.loadNpmTasks('grunt-contrib-watch')
  164. // Compress JS Files
  165. grunt.loadNpmTasks('grunt-contrib-uglify')
  166. // Include Files Within HTML
  167. grunt.loadNpmTasks('grunt-includes')
  168. // Optimize images
  169. grunt.loadNpmTasks('grunt-image')
  170. // Delete not needed files
  171. grunt.loadNpmTasks('grunt-contrib-clean')
  172. // Lint JS code
  173. grunt.loadNpmTasks('grunt-jscs')
  174. // Lint ECMA6 code
  175. grunt.loadNpmTasks('grunt-eslint')
  176. // Lint CSS
  177. grunt.loadNpmTasks('grunt-contrib-csslint')
  178. // Lint Bootstrap
  179. grunt.loadNpmTasks('grunt-bootlint')
  180. // Grunt Babel to compile ECMA6 to ECMA5
  181. grunt.loadNpmTasks('grunt-babel')
  182. // Concat files
  183. grunt.loadNpmTasks('grunt-contrib-concat')
  184. // Linting task
  185. grunt.registerTask('lint', ['jscs', 'eslint', 'csslint', 'bootlint'])
  186. // JS Build Task
  187. grunt.registerTask('build-js', ['babel', 'concat', 'uglify'])
  188. // The default task (running 'grunt' in console) is 'watch'
  189. grunt.registerTask('default', ['watch'])
  190. }