Skip to content

Instantly share code, notes, and snippets.

@behrooz-tahanzadeh
Last active February 9, 2017 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save behrooz-tahanzadeh/70a8ec78c3cb65e9013c to your computer and use it in GitHub Desktop.
Save behrooz-tahanzadeh/70a8ec78c3cb65e9013c to your computer and use it in GitHub Desktop.
Grunt description file to minify every Javascript file and put it beside its sources file
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig(
{
pkg: grunt.file.readJSON('package.json'),
uglify:
{
options:
{
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build:
{
expand:true,
src: ['<%= pkg.target %>**/*.js', '!<%= pkg.target %>**/*.min.js'],
dest: './',
ext:'.min.js'
}
},
watch:
{
scripts:
{
files: ['<%= pkg.target %>**/*.js', '!<%= pkg.target %>**/*.min.js'],
tasks: ['uglify'],
options:
{
spawn: false,
},
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task(s);
grunt.registerTask('default', ['uglify', 'watch']);
};
{
"name": "Project Name",
"version": "1.0.0",
"target": "src\/",
"devDependencies":
{
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-watch": "^0.6.1"
}
}
@behnood-eghbali
Copy link

behnood-eghbali commented Feb 9, 2017

@behrooz-tahanzadeh nobody uses grunt anymore! try gulp! :)) npm install --save-dev gulp-minify

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