2013-03-09 43 views
6

Durante l'esecuzione di grugnito, ottengo il seguente errore:grugnito compito uglify mancanza

Warning: Unable to write "client/dist/js/build.js" file (Error code: undefined). Use --force to continue.

La configurazione di uglify nel mio Gruntfile.js:

uglify: { 
     build: { 
     src: ['client/src/js/*.js'], 
     dest:['client/dist/js/build.js'] 
     } 
    } 

sto usando grunt-contrib-uglify.

Qualche idea del perché questo sta accadendo?

risposta

15

Supponendo che la versione di Grunt sia 0.4.0, AFAIK non sta utilizzando la sintassi più recente (vedere https://github.com/gruntjs/grunt-contrib-uglify#usage-examples).

Prova

uglify: { 
    build: { 
     files: { 
      'client/dist/js/build.js': ['client/src/js/*.js'] 
     } 
    } 
} 

Non sono sicuro anche se i caratteri jolly vengono gestiti correttamente.

+0

ha funzionato come un incanto, grazie. –

15

So che questo è contrassegnato come risolto, ma preferisco lo this answer from a similar question perché è possibile utilizzare nuovamente i file per un altro comando senza scriverli due volte.

In breve, la risposta dice

//Does not work 
src: ['client/src/js/*.js'], 
dest: ['client/dist/js/build.js'] 
//Works 
src: ['client/src/js/*.js'], 
dest: 'client/dist/js/build.js' 

Testato esempio lavorare senza la scrittura di file due volte:

'use strict'; 
module.exports = function(grunt) { 
    grunt.initConfig({ 
    uglify: { 
     build: { 
     src: ['client/src/js/*.js'], 
     dest: 'client/dist/js/build.js' 
     } 
    }, 
    watch: { 
     js: { 
     files: '<%= uglify.build.src %>', 
     tasks: ['uglify'] 
     } 
    } 
    }); 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.registerTask('default', [ 
    'uglify', 
    ]); 
    grunt.registerTask('dev', [ 
    'watch' 
    ]); 
}; 

noti che '<%= uglify.build.src %>' è molto utile;)

Esecuzione

$ grunt watch 
Running "watch" task 
Waiting...OK 
>> File "client/src/js/hello.js" changed. 
Running "uglify:build" (uglify) task 
File "client/dist/js/build.js" created. 
Uncompressed size: 15 bytes. 
Compressed size: 32 bytes gzipped (15 bytes minified). 

Done, without errors. 
+1

+1 questa è un'ottima soluzione. In aggiunta a questo, ho il mio package.json generato con i miei percorsi img, js e css in modo che possa fare riferimento a loro con '<% = pkg.path.js%>' ecc. – Larry