Skip to content

Instantly share code, notes, and snippets.

@Gaya
Last active May 17, 2024 03:38
Show Gist options
  • Save Gaya/7498780 to your computer and use it in GitHub Desktop.
Save Gaya/7498780 to your computer and use it in GitHub Desktop.
Gruntfile.js file for concatenation and watch tasks.
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: "\n", //add a new line after each file
banner: "", //added before everything
footer: "" //added after everything
},
dist: {
// the files to concatenate
src: [
//include libs
'libs/somelib/somelib.js',
'libs/otherlib/otherlib.js',
//own classes and files
'src/**/!(base).js',
//the last script I need
'src/base.js'
],
// the location of the resulting JS file
dest: 'js/<%= pkg.name %>.js'
}
},
watch: {
scripts: {
files: ['src/**/*.js'],
tasks: ['dev-watch'],
options: {
interrupt: true
}
}
},
removelogging: {
dist: {
src: "js/<%= pkg.name %>.js",
dest: "build/<%= pkg.name %>.js"
}
},
uglify: {
options: {
banner: ""
},
build: {
src: 'build/<%= pkg.name %>.js',
dest: 'js/<%= pkg.name %>.min.js'
}
}
});
//load the packages
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-remove-logging');
grunt.loadNpmTasks('grunt-contrib-uglify');
//register the task
grunt.registerTask('dev-watch', ['concat:dist']);
grunt.registerTask('build', ['concat', 'removelogging', 'uglify']);
};
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: "\n", //add a new line after each file
banner: "", //added before everything
footer: "" //added after everything
},
dist: {
// the files to concatenate
src: [
//include libs
'libs/somelib/somelib.js',
'libs/otherlib/otherlib.js',
//own classes and files
'src/**/!(base).js',
//the last script I need
'src/base.js'
],
// the location of the resulting JS file
dest: 'js/<%= pkg.name %>.js'
}
},
watch: {
scripts: {
files: ['src/**/*.js'],
tasks: ['dev-watch'],
options: {
interrupt: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
//register the task
grunt.registerTask('dev-watch', ['concat:dist']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment