compass-sass - 如何在 Gruntfile 中访问 Gruntfile 的绝对路径?

标签 compass-sass gruntjs

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

compass 之一 optionsimportPath .这需要一个绝对/系统路径。一个例子 importPath/system/path/to/htdocs/resources/vendor .

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

有什么办法可以访问到Gruntfile.js的路径吗?从这个文件中?

谢谢。

最佳答案

您可以利用 Node's path module .

在 gruntfile 的顶部,添加 var path = require('path'); .
path.resolve()会给你绝对路径。

关于compass-sass - 如何在 Gruntfile 中访问 Gruntfile 的绝对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18904729/

相关文章:

css - @include font-face() 出现 Compass/SASS 语法错误;

ruby-on-rails - Rails 3.1 compass 和链轮。使困惑

css - compass 1.0.0 预览文档位于何处?

java - Java 的 Compass/sass 替代品

node.js - heroku上的咕噜声和 bower

javascript - 使用 grunt 将一个函数的多个部分连接并 uglify 到一个文件中

compass-sass - 在 Sass 中包含使用变量作为名称的 mixins

php - 当我使用 grunt-php 时,如何在 *.php 中设置变量?

javascript - 如何使用 Grunt 将多个 JSON 文件加载到 Jade 模板中?

python - 通过 Grunt 运行 Python localhost