If you are looking to make your code less readable, what you're after is uglification. I came across this snippet in a tutorial about the grunt-contrib-uglify plugin online.
Setting it up is simple:
npm install grunt grunt-contrib-uglify --save-dev
This command will not only install grunt but also add uglifyjs to your node_modules devDependencies and update your package.json file accordingly.
In your Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
uglify: {
my_target: {
files: {
'dest/minified.js': ['src/jquery.js', 'src/angular.js']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify'); // load the necessary tasks
grunt.registerTask('default', ['uglify']); // The default grunt task is set to run the uglify plugin
};
Run the following command from your terminal:
$ grunt
Running "uglify:my_target" (uglify) task
1 file created.
Task complete with no errors*