Templates 如何解析gruntjs文件中的路径?
我有以下文件结构:Templates 如何解析gruntjs文件中的路径?,templates,gruntjs,Templates,Gruntjs,我有以下文件结构: application |- deploy |----- Gruntfile.js |-- package.json |-- public |----- js |-- views |----- templates 在我的Gruntfile.js文件中,我尝试编译如下所示的jade模板: module.exports = function(grunt) { var templatizer = require('templatizer'); grunt.loadNpmTa
application
|- deploy
|----- Gruntfile.js
|-- package.json
|-- public
|----- js
|-- views
|----- templates
在我的Gruntfile.js文件中,我尝试编译如下所示的jade模板:
module.exports = function(grunt) {
var templatizer = require('templatizer');
grunt.loadNpmTasks('grunt-execute');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
execute: {
templatizer: {
options: {
templatesDir: 'need path for ../views/templates', // ?
outputFile: 'need path for ../public/js/templates.js' // ?
},
call: function(grunt, options) {
templatizer(options.templatesDir, options.outputFile);
grunt.log.writeln('Templatizer done');
}
}
}
});
// Default task(s).
grunt.registerTask('default', ['execute:templatizer']);
})
我不明白如何解析templatesDir和outputFile选项的路径?使用 无论你做什么,它几乎总是错误的“误用”执行插件。搜索,如果没有插件存在,创建一个。这真的很容易 编辑: 我不喜欢GrunFile在部署目录中。在我看来,它应该始终位于项目的根目录中。如果要将其保留在部署目录中,请在那里运行,对吗?然后您的配置将如下所示(请记住:路径与Grunfile是相对的!):
我不明白。你想知道如何设置路径还是如何设置路径?对不起,我的英语很差。我需要在
templatesDir
和outputFile
选项中使用这些路径如果你像插件文档那样放置文件会发生什么?你试过了吗?在这种情况下,我会得到一个错误,因为有一级以上的文件真的吗?我把路径放在package.json文件中,然后写“../../somefolder”这样的路径,我的gruntfiles工作起来就像一个符咒。你说//路径与gruntfile相对,对吗?但这是错误的,因为GrunFile驻留在deploy目录中,请参见我的编辑。如果你不能移动你的Grunfile文件,就这样做吧谢谢你的回复。但有可能让它更漂亮吗?我的意思是,如果我移动gruntjs文件,我不想更改所有路径,该怎么办?如果你的根始终保持不变,你可以用它做一些事情,但为什么要这样做呢?只需声明一个BASE\u GRUNT\u FILE\u PATH变量并使用它,所以如果移动GrunFile,只需更改1个变量。。。
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-templatizer');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
templatizer: {
files: {
'public/js/templates.js': ['views/templates/*'] // paths are relative from your gruntfile
}
}
}
});
// Default task(s).
grunt.registerTask('default', ['templatizer']);
templatizer: {
files: {
'../public/js/templates.js': ['../views/templates/*']
}
}