Grunt.js,警告:无法写入“src”文件(错误代码:EISDIR)

时间:2014-01-07 02:38:25

标签: coffeescript gruntjs grunt-contrib-watch

我在Gruntfile中写了一个CoffeeScript,并且在(Error code: EISDIR)任务运行时我不断获得cssmin。以详细模式运行任务后,我收到以下信息:

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并成功输出到assets文件夹。 src属性中列出的路径是正确的。

知道什么可能引发错误吗?

此外,这里是整个gruntfile for 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']

3 个答案:

答案 0 :(得分:10)

在输出中,Grunt尝试运行cssmin:src任务,然后尝试写入源文件。这可能不是理想的结果吗?

您需要为cssmin任务指定一个名称,因为它是一个多任务。有关其他信息,请参阅Grunt documentation

将您的grunt配置更改为

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

答案 1 :(得分:3)

使用NodeJS 4.2.2和Grunt 0.4.5,

当编译的文件名命名为作为现有目录时,我有 EISDIR 写入错误。它们都处于相同的层次结构级别。重命名解决了这个问题。

答案 2 :(得分:0)

看来,src指向目录。尝试将/ **添加到endof路径。

资产/ z.styles.concat.css.liquid / **