如何在Grunt.js中指定目标文件夹路径与Gruntfile.js相同?

5
问题:我想配置一个名为Grunt Markdown的grunt模块,其中部分配置要求我提供目标文件的路径。我不知道如何告诉Grunt,我希望目标文件输出到与Gruntfile.js文件相同的级别。
信息:我相信文件路径是相对于Gruntfile.js的,并且我查看了文档以帮助我理解语法。下面是我的Gruntfile.js的工作示例。
module.exports = function(grunt) {

 // Project configuration.
 grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
  build: {
    src: ['js/jquery-1.7.1.min.js','js/jquery.ui.js','js/jquery.iosslider.js','js/jquery.isotope.min.js','js/jquery-css-transform.js','js/jquery-rotate.js','js/browserdetect.js','js/mainactions.js','js/min/gsapi.min.js','js/blurobjs.js','library/scripts/vallenato.js','js/soilsextension_custom.js'],
    dest: 'js/min/master.min.js'
  }
},
sass: {                              // Task
dist: {                            // Target
  options: {                       // Target options
    style: 'compressed'
  },
  files: {                         // Dictionary of files
    'css/main-child/main-child.css': 'css/main-child/main-child.scss',      // 'destination': 'source'
    'css/mobile-child/mobile-child.css': 'css/mobile-child/mobile-child.scss'
  }
}
},
concat: {
options: {
  separator: ' ',
},
dist: {
  src: ['css/main-child/main-child.css', 'css/mobile-child/mobile-child.css'],
  dest: 'css/master-child/master-child.css',
},
 },
markdown:{
all:{
  files:[
    {
      expand:true,
      src:'md/*.md',
      dest:
    }
  ]
}
},
watch: {
  scripts: {
    files: ['js/*.js'],
    tasks: ['uglify'],
    options: {
      livereload: true,
    },
  },
  css: {
    files: '**/*.scss',
    tasks: ['sass','concat'],
    options: {
      livereload: true,
    },

  }
},

imagemin: {                          // Task
    dynamic: {                         // Another target
      files: [{
        expand: true,                  // Enable dynamic expansion
        cwd: 'images/',                   // Src matches are relative to this path
        src: ['**/*.{png,jpg,gif}'],   // Actual patterns to match
        dest: 'dist/'                  // Destination path prefix
      }]
    }
  }

 });
grunt.event.on('watch', function(action, filepath, target) {
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-markdown');


// Default task(s).
grunt.registerTask('default', ['uglify']);
grunt.registerTask('default', ['sass']);
grunt.registerTask('default', ['concat']);
grunt.registerTask('default', ['watch']);
grunt.registerTask('default', ['imagemin']);
grunt.registerTask('default', ['markdown']);

};
问题: 如何告诉Grunt我的目标路径在项目的根目录下,这需要哪些语法规则(以便我以后可以参考它们)?
2个回答

3

只需使用:

markdown: {
  all: {
    files:[
      {
        expand:true,
        src: 'md/*.md',
        dest: './'          
      }
    ]
 }

0

Markdown: { all: { files:[ { expand:true, src: 'md/*.md', flatten: true } ] }

使用flatten来剥离目录结构。

谢谢


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接