我的Gruntfile.js
包含一个指南针的任务:
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
的路径?谢谢。
最佳答案
您可以利用Node's path module。
在gruntfile的顶部,添加var path = require('path');
。path.resolve()
将为您提供绝对路径。