Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = function(grunt) {
- require('load-grunt-tasks')(grunt);
- /* AVAILABLE GRUNT TASKS:
- grunt
- - runs default tasks with dev settings
- grunt serve
- - runs watch task with all dev settings + tiny local dev server
- grunt build
- - runs default tasks with production settings
- */
- grunt.initConfig({
- pkg: grunt.file.readJSON('package.json'),
- /* Stylesheet tasks for SCSS and PostCSS */
- sass: {
- dev: {
- // grunt sass:dev
- // - Enable sourcemaps
- options: {
- outputStyle: 'compressed',
- sourceMap: true
- },
- files: {
- 'deploy/css/screen.css': 'source/stylesheet/screen.scss'
- }
- },
- prod: {
- // grunt sass:prod
- // - Disable sourcemaps
- options: {
- outputStyle: 'compressed',
- sourceMap: false
- },
- files: {
- 'deploy/css/screen.css': 'source/stylesheet/screen.scss'
- }
- }
- },
- postcss: {
- // grunt postcss:dev
- // - Enable sourcemaps
- options: {
- map: true,
- processors: [
- require('autoprefixer')({ grid: true, browsers: 'last 4 versions' }),
- require('cssnano')({ zindex: false })
- ]
- },
- build: {
- files: {
- 'deploy/css/screen.css': 'deploy/css/screen.css'
- }
- }
- },
- /* JS tasks for Browserify, ESLint, and concatenating vendor JS */
- browserify: {
- dev: {
- // grunt browserify:dev
- // - Run Browserify with debug set to true
- files: {
- 'deploy/js/main.js': 'source/javascript/**/*.js'
- },
- options: {
- transform: [['vueify'], ['babelify', { presets: ['env', 'minify'] }]],
- browserifyOptions: {
- debug: true
- }
- }
- },
- prod: {
- // grunt browserify:prod
- // - Run Browserify with debug set to false
- files: {
- 'deploy/js/main.js': 'source/javascript/**/*.js'
- },
- options: {
- transform: [['vueify'], ['babelify', { presets: ['env', 'minify'] }]],
- browserifyOptions: {
- debug: false
- }
- }
- }
- },
- concat: {
- options: {
- separator: ';'
- },
- dist: {
- src: ['node_modules/list.js/dist/list.min.js', 'deploy/js/main.js'],
- dest: 'deploy/js/main.js'
- }
- },
- eslint: {
- src: 'source/javascript/**/*.js'
- },
- /* HTML tasks for includereplace templating, and HTMLHint */
- includereplace: {
- build: {
- files: [{
- src: 'source/html/*.html',
- dest: 'deploy/',
- flatten: true,
- expand: true
- }]
- }
- },
- htmlhint: {
- options: {
- htmlhintrc: '.htmlhintrc'
- },
- src: [
- 'source/html/**/*.html',
- '!source/html/components/html-header.html',
- '!source/html/components/html-footer.html']
- },
- /* Assets tasks for copying static files in source folder */
- copy: {
- /* images folder */
- assets: {
- expand: true,
- cwd: 'source',
- src: 'images/**',
- dest: 'deploy/'
- },
- /* "sharing" folder (favicons, og:images, etc) */
- sharing: {
- expand: true,
- cwd: 'source',
- src: 'sharing/**',
- dest: 'deploy/'
- },
- /* font folder */
- fonts: {
- expand: true,
- cwd: 'source',
- src: 'font/**/*',
- dest: 'deploy/'
- }
- },
- /* Local dev server task */
- connect: {
- server: {
- options: {
- base: 'deploy/',
- port: 8080,
- livereload: true
- }
- }
- },
- /* Watch tasks, runs everything except dev server */
- watch: {
- stylesheet: {
- files: ['source/stylesheet/**/*.scss'],
- tasks: ['sass:dev', 'postcss'],
- options: {
- livereload: true,
- spawn: false
- // https://git.io/vxq9v
- }
- },
- javascript: {
- files: ['source/javascript/**/*.js', 'source/javascript/components/**/*.js'],
- tasks: ['eslint', 'browserify:dev', 'concat'],
- options: {
- livereload: true
- }
- },
- html: {
- files: ['source/html/**/*.html'],
- tasks: ['includereplace', 'htmlhint'],
- options: {
- livereload: true
- }
- },
- files: {
- files: ['source/images/**', 'source/sharing/**', 'source/font/**'],
- tasks: ['copy']
- }
- }
- });
- const previous_force_state = grunt.option('force');
- grunt.registerTask('force', function(set) {
- /*
- 'force:on'
- - Force process to not exit on errors or warnings (e.g. in watch)
- 'force:off'
- - Process will do a non-zero exit on error/warn (e.g. in prod build)
- 'force:restore'
- - Reset default force value
- The global 'force' opts can be chained, meaning you can do:
- [
- 'force:on', // turns on the --force flag
- 'devtask', // will run with --force in effect
- 'force:off', // turns off the --force flag
- 'prodtask', // will run without --force flag
- 'force:restore' // restore previous --force state
- ]
- This would make the 'devtask' to never exit on error/warn, and force
- the 'prodtask' to do a non-zero exit (effectively stopping execution)
- - More info: https://git.io/d_nZfw
- */
- if (set === 'on') {
- grunt.option('force', true);
- }
- else if (set === 'off') {
- grunt.option('force', false);
- }
- else if (set === 'restore') {
- grunt.option('force', previous_force_state);
- }
- });
- /* Task for dev (default) */
- grunt.registerTask('default',
- // grunt || grunt default
- // - Runs all tasks with dev settings once and then exit
- [
- 'force:on',
- 'sass:dev',
- 'postcss',
- 'eslint',
- 'browserify:dev',
- 'concat',
- 'htmlhint',
- 'includereplace',
- 'copy',
- 'force:restore'
- ]
- );
- /* Task for production */
- grunt.registerTask('build',
- // grunt build
- // - Run all tasks with prod settings once and then exit
- [
- 'force:off',
- 'sass:prod',
- 'postcss',
- 'eslint',
- 'browserify:prod',
- 'concat',
- 'htmlhint',
- 'includereplace',
- 'copy'
- ]
- );
- grunt.registerTask('serve',
- // grunt serve
- // - Run local dev server and start watch process
- [
- 'force:restore',
- 'force:on',
- 'connect',
- 'watch'
- ]
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement