Copying Files With Grunt

From Littledamien Wiki
Revision as of 19:08, 13 May 2014 by Video8 (talk | contribs) (Created page with "== Overview == Steps for setting up a Grunt task to copy files when they are saved. == Prerequisites == * `grunt-contrib-watch`<br />This watches for changes to files. * [h...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview[edit]

Steps for setting up a Grunt task to copy files when they are saved.

Prerequisites[edit]

  • grunt-contrib-watch
    This watches for changes to files.
  • grunt-contrib-copy
    This copies files.
  • grunt-newer
    This limits the copying task to files that have been changed.
> npm install grunt-contrib-watch --save-dev
> npm install grunt-contrib-copy --save-dev
> npm install grunt-newer --save-dev

(N.B. that's grunt-newer and not grunt-contrib-newer)

gruntfile.js[edit]

module.exports = function(grunt) {
 
    // Project configuration.
    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        watch: {

            /* sync whenever anything is modified */
            sync: {
                files: ['**/*'], /* apply to everything */
                tasks: ['newer:copy']
            }
        },

        copy: {

            /* copies any file in web tree to dev sandbox */
            sandbox: {
                files: [{
                    expand: true,
                    src: [
                        '**',                   /* include everything */
                        '!/node_modules',       /* exclude grunt files */
                        '!node_modules/**/*',   
                        '!gruntfile.js',
                        '!package.json',
                        '!**/Web.config',       /* exclude localized site config files */
                        '!**/global.asa'
                    ],
                    dest: '//beckster/wwwroot/damien.mediabistro.net/'
                }]
            }
        }
    });

    /* compass compilation */
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-newer');

    // Default task(s).
    grunt.registerTask('default', ['watch']); 
};