7

我正在尝试.css从 Sass 编译文件时自动上传文件。这就是我的Gruntfile.js

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
      coffee: {
        files: ['**/*.coffee'],
        tasks: ['coffee']
      },
      scripts: {
        files: ['**/*.scss'],
        tasks: ['compass']
      },
      sftp: {
        files: ['**/*.css'],
        tasks: ['sftp-deploy']
      }
    },
    coffee: {
      compile: {
        files: {
          'testing.js': 'testing.coffee'
        }
      }
    },
    compass: {
      dist: {
        options: {
          config: 'config.rb'
        }
      }
    },

    'sftp-deploy': {
      build: {
        auth: {
          host: 'example.com',
          port: 22,
          authKey: 'key2'
        },
        src: 'styles/',
        dest: 'styles/',
        exclusions: ['**/.DS_Store'],
        server_sep: '/'
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-coffee');
  grunt.loadNpmTasks('grunt-contrib-compass');
  grunt.loadNpmTasks('grunt-sftp-deploy');


  // Default task(s).
  grunt.registerTask('default', ['watch']);

};

它编译.css但似乎没有上传它。有任何想法吗?

4

2 回答 2

2

我想确认以下 grunt-ssh ( https://github.com/andrewrjones/grunt-ssh ) 任务配置对我来说工作正常。请注意,grunt 接受 --verbose 选项,这可能有助于调试。请注意,从 v0.6.2 开始,grunt-ssh SFTP 任务似乎不支持 sshconfig 语法,这在帮助页面上不是很清楚。

    sftpCredentials: grunt.file.readJSON('sftp-credentials.json'),
    sftp: {
        deploy: {
            files: {
                "./": "deploy/**"
            },
            options: {
                "path": "<%= sftpCredentials.path %>",
                "host": "<%= sftpCredentials.host %>",
                "username": "<%= sftpCredentials.username %>",
                "port": "<%= sftpCredentials.port %>",
                "password": "<%= sftpCredentials.password %>",
                "srcBasePath": "deploy/",
                "createDirectories": true
            }
        }
    }
于 2013-08-30T04:37:11.847 回答
1

I was trying to do something almost identical using grunt-sftp and ran into similar errors. The logging wasn't the greatest so I ended up using grunt-shell and just ran scp upon compilation:

watch: {
    tumblr: {
        files:['sass/*.scss', 'sass/*/*.scss'],
        tasks: [ 'compass:tumblr', 'shell:tumblr' ]
    }
},

shell: {
  tumblr: {
    command: 'scp -P 2222 -r stylesheets "myname@myserver.com:/var/www/foo/directory"'
  }
}

This worked like a charm.

于 2013-06-04T17:08:39.463 回答