gruntfile.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. const sass = require('node-sass');
  2. module.exports = grunt => {
  3. require('load-grunt-tasks')(grunt);
  4. let port = grunt.option('port') || 8000;
  5. let root = grunt.option('root') || '.';
  6. if (!Array.isArray(root)) root = [root];
  7. // Project configuration
  8. grunt.initConfig({
  9. pkg: grunt.file.readJSON('package.json'),
  10. meta: {
  11. banner:
  12. '/*!\n' +
  13. ' * reveal.js <%= pkg.version %> (<%= grunt.template.today("yyyy-mm-dd, HH:MM") %>)\n' +
  14. ' * http://revealjs.com\n' +
  15. ' * MIT licensed\n' +
  16. ' *\n' +
  17. ' * Copyright (C) 2019 Hakim El Hattab, http://hakim.se\n' +
  18. ' */'
  19. },
  20. qunit: {
  21. files: [ 'test/*.html' ]
  22. },
  23. uglify: {
  24. options: {
  25. banner: '<%= meta.banner %>\n',
  26. ie8: true
  27. },
  28. build: {
  29. src: 'js/reveal.js',
  30. dest: 'js/reveal.min.js'
  31. }
  32. },
  33. sass: {
  34. options: {
  35. implementation: sass,
  36. sourceMap: false
  37. },
  38. core: {
  39. src: 'css/reveal.scss',
  40. dest: 'css/reveal.css'
  41. },
  42. themes: {
  43. expand: true,
  44. cwd: 'css/theme/source',
  45. src: ['*.sass', '*.scss'],
  46. dest: 'css/theme',
  47. ext: '.css'
  48. }
  49. },
  50. autoprefixer: {
  51. core: {
  52. src: 'css/reveal.css'
  53. }
  54. },
  55. cssmin: {
  56. options: {
  57. compatibility: 'ie9'
  58. },
  59. compress: {
  60. src: 'css/reveal.css',
  61. dest: 'css/reveal.min.css'
  62. }
  63. },
  64. jshint: {
  65. options: {
  66. curly: false,
  67. eqeqeq: true,
  68. immed: true,
  69. esnext: true,
  70. latedef: 'nofunc',
  71. newcap: true,
  72. noarg: true,
  73. sub: true,
  74. undef: true,
  75. eqnull: true,
  76. browser: true,
  77. expr: true,
  78. loopfunc: true,
  79. globals: {
  80. head: false,
  81. module: false,
  82. console: false,
  83. unescape: false,
  84. define: false,
  85. exports: false,
  86. require: false
  87. }
  88. },
  89. files: [ 'gruntfile.js', 'js/reveal.js' ]
  90. },
  91. connect: {
  92. server: {
  93. options: {
  94. port: port,
  95. base: root,
  96. livereload: true,
  97. open: true,
  98. useAvailablePort: true
  99. }
  100. }
  101. },
  102. zip: {
  103. bundle: {
  104. src: [
  105. 'index.html',
  106. 'css/**',
  107. 'js/**',
  108. 'lib/**',
  109. 'images/**',
  110. 'plugin/**',
  111. '**.md'
  112. ],
  113. dest: 'reveal-js-presentation.zip'
  114. }
  115. },
  116. watch: {
  117. js: {
  118. files: [ 'gruntfile.js', 'js/reveal.js' ],
  119. tasks: 'js'
  120. },
  121. theme: {
  122. files: [
  123. 'css/theme/source/*.sass',
  124. 'css/theme/source/*.scss',
  125. 'css/theme/template/*.sass',
  126. 'css/theme/template/*.scss'
  127. ],
  128. tasks: 'css-themes'
  129. },
  130. css: {
  131. files: [ 'css/reveal.scss' ],
  132. tasks: 'css-core'
  133. },
  134. test: {
  135. files: [ 'test/*.html' ],
  136. tasks: 'test'
  137. },
  138. html: {
  139. files: root.map(path => path + '/*.html')
  140. },
  141. markdown: {
  142. files: root.map(path => path + '/*.md')
  143. },
  144. options: {
  145. livereload: true
  146. }
  147. }
  148. });
  149. // Default task
  150. grunt.registerTask( 'default', [ 'css', 'js' ] );
  151. // JS task
  152. grunt.registerTask( 'js', [ 'jshint', 'uglify', 'qunit' ] );
  153. // Theme CSS
  154. grunt.registerTask( 'css-themes', [ 'sass:themes' ] );
  155. // Core framework CSS
  156. grunt.registerTask( 'css-core', [ 'sass:core', 'autoprefixer', 'cssmin' ] );
  157. // All CSS
  158. grunt.registerTask( 'css', [ 'sass', 'autoprefixer', 'cssmin' ] );
  159. // Package presentation to archive
  160. grunt.registerTask( 'package', [ 'default', 'zip' ] );
  161. // Serve presentation locally
  162. grunt.registerTask( 'serve', [ 'connect', 'watch' ] );
  163. // Run tests
  164. grunt.registerTask( 'test', [ 'jshint', 'qunit' ] );
  165. };