LoginSignup
7
7

More than 5 years have passed since last update.

Gruntfile があるディレクトリの絶対パスを取得する

Last updated at Posted at 2014-01-21

Gruntfile が設置されている場所、つまりはルートディレクトリを取得する方法について。

まずは、Gruntfile に以下の様な設定をしておく。

module.exports = (grunt) ->
  path = require 'path'

  grunt.initConfig
    rootDir: path.resolve()

そうすれば <%= rootDir %>grunt.config.data.rootDir で取得できる。

Grunt 謹製の値は無いみたいでしたが、正しい方法なのか自信がありません。

別解

コメントでご教授いただいた。

node 組み込みの __dirname 変数を使えば良かった。

module.exports = (grunt) ->
  grunt.initConfig
    rootDir: __dirname
7
7
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7