Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to config grunt.js to minify files separately

there are some js files in static/js/

    1. a.js     2. b.js     3. c.js    

how to config grunt.js to get below files:

    1. a.min.js     2. b.min.js     3. c.min.js 

as far, I have to type specific file name:

  min: {     dist: {     src:  'js/**/*.js',     dest: 'js/min/xxx.min.js'    }  } 
like image 471
looping Avatar asked Nov 13 '12 10:11

looping


People also ask

Where do you define configuration of grunt plugin?

Grunt Configuration Task configuration is specified in your Gruntfile via the grunt. initConfig method. This configuration will mostly be under task-named properties, but may contain any arbitrary data.

What is grunt Uglify?

loadNpmTasks('grunt-contrib-uglify'); } Minification of JS files can now be achieved by running the command. grunt uglify. But a task, or a set of tasks, can be run together under an "alias task". The grunt.registerTask function serves this purpose.


2 Answers

Had the same problem and found a solution that would automatically minify all my scripts separately:

uglify: {       build: {         files: [{             expand: true,             src: '**/*.js',             dest: 'build/scripts',             cwd: 'app/scripts'         }]       }     } 
like image 112
Frank Parent Avatar answered Sep 20 '22 12:09

Frank Parent


In grunt 0.4 you can specify multiple dest/src pairs like this:

uglify: {     dist: {         files: {             'dist/main.js': 'src/main.js',             'dist/widget.js': 'src/widget.js'         }     } } 
like image 36
Sindre Sorhus Avatar answered Sep 20 '22 12:09

Sindre Sorhus