【问题标题】:Gruntfile Aborting fileGruntfile 中止文件
【发布时间】:2014-01-22 21:31:56
【问题描述】:

我已经下载了foundation 5,但是在将插件添加到默认配置时遇到了问题。我从控制台的角度理解插件的安装。但是,在包含和注册任务后,我很难正确编码 Gruntfile.js

Gruntfile.js

'use strict';

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    watch: {
      options: {
          livereload: true
      },

      css: {
        files: {
            'css/app.css': 'scss/apps.css',
            'css/custom.css': 'scss/custom.scss'
        },
        tasks: ['sass', 'concat'],
        options: {
            spawn: false,
        }
      },

      scripts: {
        files: ['js/dev/*.js'],
        tasks: ['jshint', 'concat', 'uglify'],
        options: {
            spawn: false,
        }
      }
    },

    sass: {

      options: {
        includePaths: ['bower_components/foundation/scss']
      },

      dist: {
        options: {
          outputStyle: 'nested'
        },

        expand: true,
        cwd: 'scss/',
        src: {
            'css/app.css': 'scss/apps.css',
            'css/custom.css': 'scss/custom.scss'
        },
        dest: 'css/',
        ext: '.css'    
      }
    },

    jshint: {
      src: ['Gruntfile.js', 'js/dev/script.js'],
      options: {
        jshintrc: '.jshintrc',
      }
    },

    uglify: {
        build: {
            files: {
                'js/dev/plugins/*.js': ['js/dev/plugins.min.js'],
                'js/dev/script.min.js': ['js/dev/script.min.js']
            }
        }
    },

    concat : {
        bar: {
            'js/dev/script.min.js': ['js/build/script.min.js?<%= pkg.version %>']
        }
    },

    imagemin: {  
        static: {  
          options: {
            optimizationLevel: 3
          },
          files: {                         
            'lossy-images/*.png': 'images/*.png', 
            'lossy-images/*.jpg': 'images/*.jpg',
            'lossy-images/*.gif': 'images/*.gif'
          }
        },
        dynamic: {                         
          files: [{
            expand: true,                  
            cwd: 'images/',                   
            src: ['**/*.{png,jpg,gif}'],   
            dest: 'lossy-images/'                  
          }]
        }
      }

  });

  grunt.loadNpmTasks('grunt-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-imagemin');

  grunt.registerTask('build', ['sass']);
  grunt.registerTask('default', ['build','watch', 'jshint', 'concat', 'uglify', 'imagemin']);
};

包.json

{
  "name": "example-site",
  "version": "0.0.1",
  "devDependencies": {
    "node-sass": "~0.7.0",
    "grunt": "~0.4.1",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-sass": "~0.8.0",
    "grunt-contrib-jshint": "~0.8.0",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-uglify": "~0.3.1",
    "grunt-contrib-imagemin": "~0.5.0"
  }
}

.jshitrc 内容

{
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "sub": true,
  "undef": true,
  "boss": true,
  "eqnull": true,
  "node": true,
  "browser" : true,

    "globals": {
      "jQuery": true,
      "require" : true,
      "define" : true,
      "requirejs" : true,
      "describe" : true,
      "expect" : true,
      "it" : true,
      "module" : true,
    }
}

Livereload - html 代码

<script src="//localhost:35729/livereload.js"></script>

结论:

实时重新加载不起作用(我已经安装了 chrome 扩展)。我收到以下错误:

Running "sass:dist" (sass) task
Warning: Object #<Object> has no method 'indexOf' Use --force to continue.

Aborted due to warnings.

我还没有包含 compass / Autoprefixer 来满足我的 mixin 需求。如果您花时间滚动或阅读,谢谢。

欢迎任何帮助!

【问题讨论】:

    标签: javascript html json gruntjs zurb-foundation


    【解决方案1】:

    您应该尝试如下更改 sass 部分:

    sass: {
      dist: {
        options: {
          outputStyle: 'nested'
        },
    
        files: [         
          {src: 'css/app.css', dest: 'scss/apps.css'},
          {src: 'css/custom.css', dest: 'scss/custom.scss'}
        ]       
      }
    }
    

    您可以在此处找到有关文件对象格式选项的更多信息:
    http://gruntjs.com/configuring-tasks#files-object-format

    【讨论】:

    • 感谢到目前为止效果很好,你能解释一下 dist / foo / bar 之间的区别吗?我现在更好地理解了语法,但不确定调用文件和 sass 主括号之间的子括号。
    • dist/foo/bar 只是部分的名称,它可能是 ololol 以及 tratata,它只是名称,您可以使用例如萨斯:奥洛洛。
    • 我怎样才能运行一个开发版本(嵌套 css)和一个生产版本(缩小)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    相关资源
    最近更新 更多