我的Gruntfile.js包含一个指南针的任务:

grunt.initConfig({

  pkg: grunt.file.readJSON('package.json'),

  // FILE PATHS (custom)
  dir: {
    css:          'resources/styles/css',
    fonts:        'resources/fonts',
    html:         'resources/html',
    images:       'resources/images',
    includes:     'resources/includes',
    node_modules: 'node_modules',
    prototypes:   'resources/html/prototypes',
    resources:    'resources',
    scripts:      'resources/scripts',
    scss:         'resources/styles/scss',
    styles:       'resources/styles',
    styleguide:   'resources/styleguide',
    vendor:       'resources/vendor',
    user: {
       htdocs: '/Volumes/VR\ Mini\ Backup/Backups/Web/Active/myproject/htdocs'
    }
  },

  // COMPASS
  compass: {
    dist: {
      options: {
        ...
        importPath: [
          '<%= dir.user.htdocs %>/<%= dir.resources %>/vendor',
          '<%= dir.user.htdocs %>/<%= dir.resources %>/fonts'
        ]


指南针options之一是importPath。这需要绝对/系统路径。 importPath的示例是/system/path/to/htdocs/resources/vendor

由于有几个开发人员将在我的项目上工作,所以我想使/system/path/to/htdocs动态。

有什么方法可以从此文件中访问Gruntfile.js的路径?

谢谢。

最佳答案

您可以利用Node's path module

在gruntfile的顶部,添加var path = require('path');

path.resolve()将为您提供绝对路径。

10-05 21:06
查看更多