2014-01-07 59 views
12

我有一個Gruntfile寫在CoffeeScript,並且在cssmin任務運行時我總是收到(Error code: EISDIR)。運行在詳細模式下任務後,我得到這樣的信息:Grunt.js,警告:無法寫入「src」文件(錯誤代碼:EISDIR)

Running "cssmin" task 

Running "cssmin:src" (cssmin) task 
Verifying property cssmin.src exists in config...OK 
Files: assets/z.styles.concat.css.liquid -> src 
Options: report=false 
Reading assets/z.styles.concat.css.liquid...OK 
Writing src...ERROR 
Warning: Unable to write "src" file (Error code: EISDIR). Use --force to continue. 

這裏是我的cssmin任務:

cssmin: 
     src: 'assets/z.styles.concat.css.liquid' 
     dest: 'assets/styles.min.css.liquid' 

z.styles.concat.css.liquid之後concat運行創建併成功輸出到資產的文件夾。 src屬性中列出的路徑是正確的。

任何想法可能會拋出錯誤?

此外,這裏是整個gruntfile爲connivence。

Grunt.coffee:

module.exports = (grunt) -> 

# Project configuration. 
    grunt.initConfig 
    pkg: grunt.file.readJSON 'package.json' 

    files: 
     grunt:  ['gruntfile.js'] 
     css:  ['assets/screen.css', 'assets/styles.css.liquid'] 
     scss:  ['src/scss/**/*.scss'] 
     js:  ['src/js/**/*.js'] #(if we need liquid templating), 'src/js/**/*.js.liquid', 'assets/**/*.js.liquid'] 
     coffee: ['src/js/coffee/**/*.coffee', 'src/js/coffee/**/*.coffee.liquid'] 
     img:  ['src/images/**/*.{png,jpeg,svg,jpg,gif}'] 

# Image Processing 
    smushit: 
     path: 
     src: '<%= files.img %>' #recursively replace minified images 
     dest: 'assets' 

# Concatenation Processing 
    concat: 
     css: 
     src: ['<%= files.css %>'] 
     dest: 'assets/z.styles.concat.css.liquid'  

     js: 
     src: ['<%= files.js %>'] 
     dest: 'src/js/z.scripts.concat.js' 


# JavaScript Processing 
    coffee: 
      app: 
      expand: true 
      cwd: 'src/js/coffee' 
      src: ['**/*.coffee', '**/*.coffee.liquid'] 
      dest: 'src/js' 
      ext: '.js' 

    uglify: 
     dist: 
     src: ['src/js/z.scripts.concat.js'] 
     dest: 'assets/scripts.min.js' 

    jshint: 
     files: ['<%= files.grunt %>', 'src/js/z.scripts.concat.js'] 

     options: 
     jquery: true 
     smarttabs: true 
     curly: true 
     eqeqeq: true 
     immed: true 
     latedef: true 
     newcap: true 
     noarg: true 
     sub: true 
     undef: true 
     boss: true 
     eqnull: true 
     browser: true 

     globals: 
     jQuery: true 
     console: true 
     undef: true 
     unused: false 



# CSS Processing 
    compass: 
     dist: 
     options: 
      sassDir: 'src/scss' 
      cssDir: 'assets' 
      imagesDir: 'assets', 
      javascriptsDir: 'assets', 
      outputStyle: 'expanded' 

    cssmin: 
     src: 'assets/z.styles.concat.css.liquid' 
     dest: 'assets/styles.min.css.liquid' 


# watch tasks 
    watch: 
     options: 
     nospawn: true 
     events: ['changed', 'added'] 
     files: [ 
       '<%= files.js %>' 
       '<%= files.coffee %>' 
       '<%= files.scss %>' 
      ] 
     tasks: ['default'] 

    # These plugins provide necessary tasks. 
    grunt.loadNpmTasks 'grunt-contrib-coffee' 
    grunt.loadNpmTasks 'grunt-contrib-watch' 
    grunt.loadNpmTasks 'grunt-contrib-concat' 
    grunt.loadNpmTasks 'grunt-contrib-jshint' 
    grunt.loadNpmTasks 'grunt-contrib-uglify' 
    grunt.loadNpmTasks 'grunt-contrib-cssmin' 
    grunt.loadNpmTasks 'grunt-smushit' 
    grunt.loadNpmTasks 'grunt-contrib-compass' 

# Default task. 
    grunt.registerTask 'default', [ 
         'coffee' 
         'concat:js' 
         'jshint' 
         'uglify' 
         'concat:css', 
         'cssmin' 
        ] 

    # Minify task 

    # Run the default task then losslessly minify images with Yahoo!'s Smush-It 

    grunt.registerTask 'minify', ['default', 'smushit'] 
+0

你可以嘗試使用--verbose選項運行任務嗎? –

+1

只要運行咕嚕your_task_name --verbose –

+0

@AndreyShustariov剛剛更新的問題 – agconti

回答

9

在你的輸出咕嚕的嘗試運行cssmin:src任務,然後它會嘗試寫源文件。這不可能是期望的結果?

您需要爲cssmin任務指定一個名稱,因爲它是多任務處理。請參閱Grunt documentation瞭解更多信息。

你的咕嚕配置更改爲

cssmin: 
    minify: 
     src: 'assets/z.styles.concat.css.liquid' 
     dest: 'assets/styles.min.css.liquid' 
+0

賓果芽!任何想法爲什麼這個任務必須命名? – agconti

+2

我認爲,因爲它是一項多任務:http://gruntjs.com/creating-tasks#multi-tasks – thomaux

+0

太棒了!感謝您的鏈接。 – agconti

0

看來,SRC指向的目錄。嘗試將/ **添加到endof路徑。

資產/ z.styles.concat.css.liquid/**

+0

'運行「cssmin:SRC」(cssmin)任務 >>目的地不寫,因爲精縮CSS是empty.' – agconti

+0

基本上我認爲,這只是它告訴給尋找一個不存在的目錄。 – agconti

+0

正如我記得,代碼EISDIR的意思是,該目錄被作爲文件訪問。 –

3

使用4.2.2的NodeJS和咕嚕0.4.5,

EISDIR寫入錯誤時,編譯了文件名命名相同作爲現有目錄。他們都在同一個層次。重命名解決了這個問題。

相關問題