本文介绍了Grunt - 当文件和SFTP发生变化时观看文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Sass编译时自动上传 .css 文件。这就是我在 Gruntfile.js 中得到的结果:

I'm trying to automatically upload a .css file, when it's compiled from Sass. This is what I've got in my 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 ,但不会'似乎上传它。任何想法?

It compiles the .css but doesn't seem to upload it. Any ideas?

推荐答案

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

I would like to confirm that the following grunt-ssh (https://github.com/andrewrjones/grunt-ssh) task config worked fine for me. Note that grunt accepts --verbose option which may help debug. Note that as of v0.6.2 grunt-ssh SFTP task did not seem to support sshconfig syntax, which was not very clear from the help page.

    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
            }
        }
    }

这篇关于Grunt - 当文件和SFTP发生变化时观看文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 15:01