15

My Gruntfile.js contains a task for Compass:

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'
        ]

One of the Compass options is importPath. This expects an absolute/system path. An example importPath is /system/path/to/htdocs/resources/vendor.

As several developers will be working on my project, I'd like to make /system/path/to/htdocs dynamic.

Is there any way to access the path to Gruntfile.js from within this file?

Thanks.

Dan
  • 423
  • 4
  • 9

1 Answers1

24

You can leverage Node's path module.

At the top of your gruntfile, add var path = require('path');.

path.resolve() will give you the absolute path.

max
  • 5,979
  • 2
  • 21
  • 16