首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问Gruntfile中的Gruntfile绝对路径?

如何访问Gruntfile中的Gruntfile绝对路径?
EN

Stack Overflow用户
提问于 2013-09-19 20:54:53
回答 1查看 5.7K关注 0票数 15

我的Gruntfile.js包含一个用于Compass的任务:

代码语言:javascript
复制
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'
        ]

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

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

有任何方法可以从这个文件中访问Gruntfile.js的路径吗?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-19 23:44:07

你可以利用节点路径模块

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

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

票数 24
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18904729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档