【问题标题】:How to access absolute path to Gruntfile within Gruntfile?如何在 Gruntfile 中访问 Gruntfile 的绝对路径?
【发布时间】:2013-09-20 07:44:07
【问题描述】:

我的Gruntfile.js 包含 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'
        ]

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

由于多个开发人员将参与我的项目,我想让/system/path/to/htdocs 动态化。

有没有办法从这个文件中访问Gruntfile.js 的路径?

谢谢。

【问题讨论】:

    标签: compass-sass gruntjs


    【解决方案1】:

    您可以利用Node's path module

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

    path.resolve() 会给你绝对路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 2017-03-04
      相关资源
      最近更新 更多