Skip to content

Instantly share code, notes, and snippets.

@sukrosono
Created March 9, 2016 18:21
Show Gist options
  • Save sukrosono/83b0296a536cb923073b to your computer and use it in GitHub Desktop.
Save sukrosono/83b0296a536cb923073b to your computer and use it in GitHub Desktop.
run grunt from different directory for building submodule
module.exports = function(grunt) {
'use strict';
var parent_module = '../../node_modules/';
grunt.loadTasks(parent_module + 'grunt-contrib-watch/tasks');
grunt.loadTasks(parent_module+'grunt-contrib-concat/tasks');
grunt.loadTasks(parent_module+'grunt-contrib-uglify/tasks');
grunt.initConfig({
pkg: grunt.file.readJSON('../../package.json'),
concat: {
options: {
separator: '//#######################################################\n'
},
dist: {
src: [
'**/*.module.js',
'**/*.state.js',
'**/*.config.js',
'**/*.run.js',
'**/*.js'
],
dest: '../../dist/<%= pkg.name %>-submodule.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %>-submodule - v <%= pkg.version %> - by <%= pkg.author %>' +
' <%= grunt.template.today("dd-mmmm-yyyy")%> */\n',
sourceMap: true
},
dist: {
files: {
'../../dist/<%= pkg.name %>-submodule.min.js': ['<%= concat.dist.dest %>']
}
}
},
watch: {
js: {
files: ['<%= concat.dist.src %>']
},
options: {
nospawn: true
}
// tasks: ['build'] not work here
}
});
grunt.event.on('watch', function(action, filepath, target) {
grunt.log.writeln(target + ': ' + filepath + ' has ' + action+' defined by enter on grunt event');
// achievable via
grunt.task.run('build');
});
grunt.registerTask('build', ['concat', 'uglify']);
grunt.registerTask('default', ['watch']);
};
@sukrosono
Copy link
Author

My env :

node: v4.2.6
npm: 3.7.4
"grunt": "^0.4.5",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-uglify": "^0.11.0",
"grunt-contrib-watch": "^0.6.1",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment