Advertisement
Guest User

Untitled

a guest
May 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = function(grunt) {
  2.     require('load-grunt-tasks')(grunt);
  3.  
  4.     /* AVAILABLE GRUNT TASKS:
  5.         grunt
  6.             - runs default tasks with dev settings
  7.         grunt serve
  8.             - runs watch task with all dev settings + tiny local dev server
  9.         grunt build
  10.             - runs default tasks with production settings
  11.     */
  12.  
  13.     grunt.initConfig({
  14.         pkg: grunt.file.readJSON('package.json'),
  15.  
  16.         /* Stylesheet tasks for SCSS and PostCSS */
  17.         sass: {
  18.             dev: {
  19.                 // grunt sass:dev
  20.                 // - Enable sourcemaps
  21.                 options: {
  22.                     outputStyle: 'compressed',
  23.                     sourceMap: true
  24.                 },
  25.                 files: {
  26.                     'deploy/css/screen.css': 'source/stylesheet/screen.scss'
  27.                 }
  28.             },
  29.             prod: {
  30.                 // grunt sass:prod
  31.                 // - Disable sourcemaps
  32.                 options: {
  33.                     outputStyle: 'compressed',
  34.                     sourceMap: false
  35.                 },
  36.                 files: {
  37.                     'deploy/css/screen.css': 'source/stylesheet/screen.scss'
  38.                 }
  39.             }
  40.         },
  41.  
  42.         postcss: {
  43.             // grunt postcss:dev
  44.             // - Enable sourcemaps
  45.             options: {
  46.                 map: true,
  47.                 processors: [
  48.                     require('autoprefixer')({ grid: true, browsers: 'last 4 versions' }),
  49.                     require('cssnano')({ zindex: false })
  50.                 ]
  51.             },
  52.             build: {
  53.                 files: {
  54.                     'deploy/css/screen.css': 'deploy/css/screen.css'
  55.                 }
  56.             }
  57.         },
  58.  
  59.         /* JS tasks for Browserify, ESLint, and concatenating vendor JS */
  60.         browserify: {
  61.             dev: {
  62.                 // grunt browserify:dev
  63.                 // - Run Browserify with debug set to true
  64.                 files: {
  65.                     'deploy/js/main.js': 'source/javascript/**/*.js'
  66.                 },
  67.                 options: {
  68.                     transform: [['vueify'], ['babelify', { presets: ['env', 'minify'] }]],
  69.                     browserifyOptions: {
  70.                         debug: true
  71.                     }
  72.                 }
  73.             },
  74.             prod: {
  75.                 // grunt browserify:prod
  76.                 // - Run Browserify with debug set to false
  77.                 files: {
  78.                     'deploy/js/main.js': 'source/javascript/**/*.js'
  79.                 },
  80.                 options: {
  81.                     transform: [['vueify'], ['babelify', { presets: ['env', 'minify'] }]],
  82.                     browserifyOptions: {
  83.                         debug: false
  84.                     }
  85.                 }
  86.             }
  87.         },
  88.  
  89.         concat: {
  90.             options: {
  91.                 separator: ';'
  92.             },
  93.             dist: {
  94.                 src: ['node_modules/list.js/dist/list.min.js', 'deploy/js/main.js'],
  95.                 dest: 'deploy/js/main.js'
  96.             }
  97.         },
  98.  
  99.         eslint: {
  100.             src: 'source/javascript/**/*.js'
  101.         },
  102.  
  103.         /* HTML tasks for includereplace templating, and HTMLHint */
  104.         includereplace: {
  105.             build: {
  106.                 files: [{
  107.                     src: 'source/html/*.html',
  108.                     dest: 'deploy/',
  109.                     flatten: true,
  110.                     expand: true
  111.                 }]
  112.             }
  113.         },
  114.  
  115.         htmlhint: {
  116.             options: {
  117.                 htmlhintrc: '.htmlhintrc'
  118.             },
  119.             src: [
  120.                 'source/html/**/*.html',
  121.                 '!source/html/components/html-header.html',
  122.                 '!source/html/components/html-footer.html']
  123.         },
  124.  
  125.         /* Assets tasks for copying static files in source folder */
  126.         copy: {
  127.             /* images folder */
  128.             assets: {
  129.                 expand: true,
  130.                 cwd: 'source',
  131.                 src: 'images/**',
  132.                 dest: 'deploy/'
  133.             },
  134.             /* "sharing" folder (favicons, og:images, etc) */
  135.             sharing: {
  136.                 expand: true,
  137.                 cwd: 'source',
  138.                 src: 'sharing/**',
  139.                 dest: 'deploy/'
  140.             },
  141.             /* font folder */
  142.             fonts: {
  143.                 expand: true,
  144.                 cwd: 'source',
  145.                 src: 'font/**/*',
  146.                 dest: 'deploy/'
  147.             }
  148.         },
  149.  
  150.         /* Local dev server task */
  151.         connect: {
  152.             server: {
  153.                 options: {
  154.                     base: 'deploy/',
  155.                     port: 8080,
  156.                     livereload: true
  157.                 }
  158.             }
  159.         },
  160.  
  161.         /* Watch tasks, runs everything except dev server */
  162.         watch: {
  163.             stylesheet: {
  164.                 files: ['source/stylesheet/**/*.scss'],
  165.                 tasks: ['sass:dev', 'postcss'],
  166.                 options: {
  167.                     livereload: true,
  168.                     spawn: false
  169.                     // https://git.io/vxq9v
  170.                 }
  171.             },
  172.  
  173.             javascript: {
  174.                 files: ['source/javascript/**/*.js', 'source/javascript/components/**/*.js'],
  175.                 tasks: ['eslint', 'browserify:dev', 'concat'],
  176.                 options: {
  177.                     livereload: true
  178.                 }
  179.             },
  180.  
  181.             html: {
  182.                 files: ['source/html/**/*.html'],
  183.                 tasks: ['includereplace', 'htmlhint'],
  184.                 options: {
  185.                     livereload: true
  186.                 }
  187.             },
  188.  
  189.             files: {
  190.                 files: ['source/images/**', 'source/sharing/**', 'source/font/**'],
  191.                 tasks: ['copy']
  192.             }
  193.         }
  194.     });
  195.  
  196.     const previous_force_state = grunt.option('force');
  197.  
  198.     grunt.registerTask('force', function(set) {
  199.         /*
  200.         'force:on'
  201.             - Force process to not exit on errors or warnings (e.g. in watch)
  202.         'force:off'
  203.             - Process will do a non-zero exit on error/warn (e.g. in prod build)
  204.         'force:restore'
  205.             - Reset default force value
  206.  
  207.         The global 'force' opts can be chained, meaning you can do:
  208.             [
  209.                 'force:on',     // turns on the --force flag
  210.                 'devtask',      // will run with --force in effect
  211.                 'force:off',    // turns off the --force flag
  212.                 'prodtask',     // will run without --force flag
  213.                 'force:restore' // restore previous --force state
  214.             ]
  215.         This would make the 'devtask' to never exit on error/warn, and force
  216.         the 'prodtask' to do a non-zero exit (effectively stopping execution)
  217.         - More info: https://git.io/d_nZfw
  218.         */
  219.  
  220.         if (set === 'on') {
  221.             grunt.option('force', true);
  222.         }
  223.         else if (set === 'off') {
  224.             grunt.option('force', false);
  225.         }
  226.         else if (set === 'restore') {
  227.             grunt.option('force', previous_force_state);
  228.         }
  229.     });
  230.  
  231.     /* Task for dev (default) */
  232.     grunt.registerTask('default',
  233.         // grunt || grunt default
  234.         // - Runs all tasks with dev settings once and then exit
  235.         [
  236.             'force:on',
  237.             'sass:dev',
  238.             'postcss',
  239.             'eslint',
  240.             'browserify:dev',
  241.             'concat',
  242.             'htmlhint',
  243.             'includereplace',
  244.             'copy',
  245.             'force:restore'
  246.         ]
  247.     );
  248.  
  249.     /* Task for production */
  250.     grunt.registerTask('build',
  251.         // grunt build
  252.         // - Run all tasks with prod settings once and then exit
  253.         [
  254.             'force:off',
  255.             'sass:prod',
  256.             'postcss',
  257.             'eslint',
  258.             'browserify:prod',
  259.             'concat',
  260.             'htmlhint',
  261.             'includereplace',
  262.             'copy'
  263.         ]
  264.     );
  265.  
  266.     grunt.registerTask('serve',
  267.         // grunt serve
  268.         // - Run local dev server and start watch process
  269.         [
  270.             'force:restore',
  271.             'force:on',
  272.             'connect',
  273.             'watch'
  274.         ]
  275.     );
  276. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement