public
Created

gruntfile

  • Download Gist
gruntfile.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
var fs = require('fs');
var path = require('path');
var sweet = require('sweet.js');
 
module.exports = function(grunt) {
grunt.initConfig({
sweetjs: {
options: {
modules: ['es6-macros'],
sourceMap: true,
nodeSourceMapSupport: true
},
server: {
files: [{
expand: true,
cwd: 'src/',
src: ['**/*.js'],
dest: 'build/'
}]
},
client: {
options: {
nodeSourceMapSupport: false
},
files: [{
expand: true,
cwd: 'static/js/',
src: ['**/*.js', '!lib/**/*.js'],
dest: 'static/js-build/'
}]
}
},
copy: {
client: {
files: [{
expand: true,
cwd: 'static/js/',
src: ['lib/**/*.js'],
dest: 'static/js-build/'
}]
}
},
watch: {
options: {
nospawn: true
},
server_js: {
files: ['src/**/*.js'],
tasks: ['sweetjs:server']
},
client_js: {
files: ['static/js/**/*.js'],
tasks: ['sweetjs:client']
}
}
});
 
grunt.event.on('watch', function(action, filepath, target) {
if(action == 'changed') {
var dest, cmd;
if(target == 'server_js') {
dest = filepath.replace(/^src/, 'build');
cmd = 'sweetjs.server';
}
else {
dest = filepath.replace(/^static\/js/, 'static/js-build');
cmd = 'sweetjs.client';
}
 
grunt.config.set(cmd + '.src', [filepath]);
grunt.config.set(cmd + '.dest', dest);
}
else if(action == 'deleted') {
// remove files in build
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-sweet.js');
 
grunt.registerTask('default', ['sweetjs', 'copy']);
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.