Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 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