Gruntfile.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * @file
  3. */
  4. module.exports = function(grunt) {
  5. // This is where we configure each task that we'd like to run.
  6. grunt.initConfig({
  7. pkg: grunt.file.readJSON('package.json'),
  8. watch: {
  9. // This is where we set up all the tasks we'd like grunt to watch for changes.
  10. scripts: {
  11. files: ['js/source/**/*.js'],
  12. tasks: ['uglify'],
  13. options: {
  14. spawn: false,
  15. },
  16. },
  17. images: {
  18. files: ['images/source/**/*.{png,jpg,gif}'],
  19. tasks: ['imagemin'],
  20. options: {
  21. spawn: false,
  22. }
  23. },
  24. vector: {
  25. files: ['images/source/**/*.svg'],
  26. tasks: ['svgmin'],
  27. options: {
  28. spawn: false,
  29. }
  30. },
  31. css: {
  32. files: ['sass/**/*.{scss,sass}'],
  33. tasks: ['sass', 'postcss']
  34. }
  35. },
  36. uglify: {
  37. // This is for minifying all of our scripts.
  38. options: {
  39. sourceMap: true,
  40. mangle: false
  41. },
  42. my_target: {
  43. files: [{
  44. expand: true,
  45. cwd: 'js/source',
  46. src: '**/*.js',
  47. dest: 'js/build'
  48. }]
  49. }
  50. },
  51. imagemin: {
  52. // This will optimize all of our images for the web.
  53. dynamic: {
  54. files: [{
  55. expand: true,
  56. cwd: 'images/source/',
  57. src: ['**/*.{png,jpg,gif}'],
  58. dest: 'images/optimized/'
  59. }]
  60. }
  61. },
  62. svgmin: {
  63. options: {
  64. plugins: [{
  65. removeViewBox: false
  66. }, {
  67. removeUselessStrokeAndFill: false
  68. }]
  69. },
  70. dist: {
  71. files: [{
  72. expand: true,
  73. cwd: 'images/source/',
  74. src: ['**/*.svg'],
  75. dest: 'images/optimized/'
  76. }]
  77. }
  78. },
  79. sass: {
  80. // This will compile all of our sass files
  81. // Additional configuration options can be found at https://github.com/sindresorhus/grunt-sass
  82. options: {
  83. sourceMap: true,
  84. // This controls the compiled css and can be changed to nested, compact or compressed.
  85. outputStyle: 'expanded',
  86. precision: 5
  87. },
  88. dist: {
  89. files: {
  90. 'css/base/base.css': 'sass/base/base.sass',
  91. 'css/components/components.css': 'sass/components/components.sass',
  92. 'css/components/tabs.css': 'sass/components/tabs.sass',
  93. 'css/components/messages.css': 'sass/components/messages.sass',
  94. 'css/layout/layout.css': 'sass/layout/layout.sass',
  95. 'css/theme/theme.css': 'sass/theme/theme.sass',
  96. 'css/theme/print.css': 'sass/theme/print.sass'
  97. }
  98. }
  99. },
  100. postcss:{
  101. options: {
  102. processors: [
  103. require('pixrem')(),
  104. require('autoprefixer')({browsers: 'last 5 versions'})
  105. ]
  106. },
  107. dist:{
  108. files:{
  109. 'css/base/base.css': 'css/base/base.css',
  110. 'css/components/components.css': 'css/components/components.css',
  111. 'css/components/tabs.css': 'css/components/tabs.css',
  112. 'css/components/messages.css': 'css/components/messages.css',
  113. 'css/layout/layout.css': 'css/layout/layout.css',
  114. 'css/theme/theme.css': 'css/theme/theme.css',
  115. 'css/theme/print.css': 'css/theme/print.css'
  116. }
  117. }
  118. },
  119. browserSync: {
  120. dev: {
  121. bsFiles: {
  122. src : [
  123. 'css/**/*.css',
  124. 'templates/**/*.twig',
  125. 'images/optimized/**/*.{png,jpg,gif,svg}',
  126. 'js/build/**/*.js',
  127. '*.theme'
  128. ]
  129. },
  130. options: {
  131. watchTask: true,
  132. // Change this to "true" if you'd like the css to be injected rather than a browser refresh. In order for this to work with Drupal you will need to install https://drupal.org/project/link_css keep in mind though that this should not be run on a production site.
  133. injectChanges: false
  134. }
  135. }
  136. },
  137. });
  138. // This is where we tell Grunt we plan to use this plug-in.
  139. grunt.loadNpmTasks('grunt-contrib-uglify');
  140. grunt.loadNpmTasks('grunt-contrib-imagemin');
  141. grunt.loadNpmTasks('grunt-svgmin');
  142. grunt.loadNpmTasks('grunt-sass');
  143. grunt.loadNpmTasks('grunt-postcss');
  144. grunt.loadNpmTasks('grunt-contrib-watch');
  145. grunt.loadNpmTasks('grunt-browser-sync');
  146. // Now that we've loaded the package.json and the node_modules we set the base path
  147. // for the actual execution of the tasks
  148. // grunt.file.setBase('/')
  149. // This is where we tell Grunt what to do when we type "grunt" into the terminal.
  150. // Note: if you'd like to run and of the tasks individually you can do so by typing 'grunt mytaskname' alternatively
  151. // you can type 'grunt watch' to automatically track your files for changes.
  152. grunt.registerTask('default', ['browserSync','watch']);
  153. };