Skip to content

Instantly share code, notes, and snippets.

@jlongster
Created December 19, 2013 20:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jlongster/8045898 to your computer and use it in GitHub Desktop.
Save jlongster/8045898 to your computer and use it in GitHub Desktop.
gruntfile
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']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment