Posted By

rickygri on 07/05/13


Tagged


Versions (?)

Grunt boilerplate


 / Published in: JavaScript
 

URL: http://integralist.co.uk/Grunt-Boilerplate.html

Copypasta boilerplate for command prompt node install

  1. module.exports = function (grunt) {
  2.  
  3. /*
  4.   Grunt installation:
  5.   -------------------
  6.   npm install -g grunt-cli
  7.   npm install -g grunt-init
  8.   npm init (creates a `package.json` file)
  9.  
  10.   Project Dependencies:
  11.   ---------------------
  12.   npm install grunt --save-dev
  13.   npm install grunt-contrib-watch --save-dev
  14.   npm install grunt-contrib-jshint --save-dev
  15.   npm install grunt-contrib-uglify --save-dev
  16.   npm install grunt-contrib-requirejs --save-dev
  17.   npm install grunt-contrib-sass --save-dev
  18.   npm install grunt-contrib-imagemin --save-dev
  19.   npm install grunt-contrib-htmlmin --save-dev
  20.   npm install grunt-contrib-connect --save-dev
  21.   npm install grunt-contrib-jasmine --save-dev
  22.   npm install grunt-template-jasmine-requirejs --save-dev
  23.   */
  24.  
  25. // Project configuration.
  26. grunt.initConfig({
  27.  
  28. // Store your Package file so you can reference its specific data whenever necessary
  29. pkg: grunt.file.readJSON('package.json'),
  30.  
  31. // Used to connect to a locally running web server (so Jasmine can test against a DOM)
  32. connect: {
  33. test: {
  34. port: 8000
  35. }
  36. },
  37.  
  38. jasmine: {
  39. /*
  40.   Note:
  41.   In case there is a /release/ directory found, we don't want to run tests on that
  42.   so we use the ! (bang) operator to ignore the specified directory
  43.   */
  44. src: ['app/**/*.js', '!app/release/**'],
  45. options: {
  46. host: 'http://127.0.0.1:8000/',
  47. specs: 'specs/**/*Spec.js',
  48. helpers: ['specs/helpers/*Helper.js', 'specs/helpers/sinon.js'],
  49. template: require('grunt-template-jasmine-requirejs'),
  50. templateOptions: {
  51. requireConfig: {
  52. baseUrl: './app/',
  53. mainConfigFile: './app/main.js'
  54. }
  55. }
  56. }
  57. },
  58.  
  59. jshint: {
  60. /*
  61.   Note:
  62.   In case there is a /release/ directory found, we don't want to lint that
  63.   so we use the ! (bang) operator to ignore the specified directory
  64.   */
  65. files: ['Gruntfile.js', 'app/**/*.js', '!app/release/**', 'modules/**/*.js', 'specs/**/*Spec.js'],
  66. options: {
  67. curly: true,
  68. eqeqeq: true,
  69. immed: true,
  70. latedef: true,
  71. newcap: true,
  72. noarg: true,
  73. sub: true,
  74. undef: true,
  75. boss: true,
  76. eqnull: true,
  77. browser: true,
  78.  
  79. globals: {
  80. // AMD
  81. module: true,
  82. require: true,
  83. requirejs: true,
  84. define: true,
  85.  
  86. // Environments
  87. console: true,
  88.  
  89. // General Purpose Libraries
  90. $: true,
  91. jQuery: true,
  92.  
  93. // Testing
  94. sinon: true,
  95. describe: true,
  96. it: true,
  97. expect: true,
  98. beforeEach: true,
  99. afterEach: true
  100. }
  101. }
  102. },
  103.  
  104. requirejs: {
  105. compile: {
  106. options: {
  107. baseUrl: './app',
  108. mainConfigFile: './app/main.js',
  109. dir: './app/release/',
  110. fileExclusionRegExp: /^\.|node_modules|Gruntfile|\.md|package.json/,
  111. // optimize: 'none',
  112. modules: [
  113. {
  114. name: 'main'
  115. // include: ['module'],
  116. // exclude: ['module']
  117. }
  118. ]
  119. }
  120. }
  121. },
  122.  
  123. sass: {
  124. dist: {
  125. options: {
  126. style: 'compressed',
  127. require: ['./assets/styles/sass/helpers/url64.rb']
  128. },
  129. expand: true,
  130. cwd: './app/styles/sass/',
  131. src: ['*.scss'],
  132. dest: './app/styles/',
  133. ext: '.css'
  134. },
  135. dev: {
  136. options: {
  137. style: 'expanded',
  138. debugInfo: true,
  139. lineNumbers: true,
  140. require: ['./app/styles/sass/helpers/url64.rb']
  141. },
  142. expand: true,
  143. cwd: './app/styles/sass/',
  144. src: ['*.scss'],
  145. dest: './app/styles/',
  146. ext: '.css'
  147. }
  148. },
  149.  
  150. // `optimizationLevel` is only applied to PNG files (not JPG)
  151. imagemin: {
  152. png: {
  153. options: {
  154. optimizationLevel: 7
  155. },
  156. files: [
  157. {
  158. expand: true,
  159. cwd: './app/images/',
  160. src: ['**/*.png'],
  161. dest: './app/images/compressed/',
  162. ext: '.png'
  163. }
  164. ]
  165. },
  166. jpg: {
  167. options: {
  168. progressive: true
  169. },
  170. files: [
  171. {
  172. expand: true,
  173. cwd: './app/images/',
  174. src: ['**/*.jpg'],
  175. dest: './app/images/compressed/',
  176. ext: '.jpg'
  177. }
  178. ]
  179. }
  180. },
  181.  
  182. htmlmin: {
  183. dist: {
  184. options: {
  185. removeComments: true,
  186. collapseWhitespace: true,
  187. removeEmptyAttributes: true,
  188. removeCommentsFromCDATA: true,
  189. removeRedundantAttributes: true,
  190. collapseBooleanAttributes: true
  191. },
  192. files: {
  193. // Destination : Source
  194. './index-min.html': './index.html'
  195. }
  196. }
  197. },
  198.  
  199. // Run: `grunt watch` from command line for this section to take effect
  200. watch: {
  201. files: ['<%= jshint.files %>', '<%= jasmine.options.specs %>', '<%= sass.dev.src %>'],
  202. tasks: 'default'
  203. }
  204.  
  205. });
  206.  
  207. // Load NPM Tasks
  208. grunt.loadNpmTasks('grunt-contrib-watch');
  209. grunt.loadNpmTasks('grunt-contrib-jshint');
  210. grunt.loadNpmTasks('grunt-contrib-uglify');
  211. grunt.loadNpmTasks('grunt-contrib-requirejs');
  212. grunt.loadNpmTasks('grunt-contrib-sass');
  213. grunt.loadNpmTasks('grunt-contrib-imagemin');
  214. grunt.loadNpmTasks('grunt-contrib-htmlmin');
  215. grunt.loadNpmTasks('grunt-contrib-connect');
  216. grunt.loadNpmTasks('grunt-contrib-jasmine');
  217.  
  218. // Default Task
  219. grunt.registerTask('default', ['jshint', 'connect', 'jasmine', 'sass:dev']);
  220.  
  221. // Unit Testing Task
  222. grunt.registerTask('test', ['connect', 'jasmine']);
  223.  
  224. // Release Task
  225. grunt.registerTask('release', ['jshint', 'jasmine', 'requirejs', 'sass:dist', 'imagemin', 'htmlmin']);
  226.  
  227. };

Report this snippet  

You need to login to post a comment.