Grunt nunjucks-2-html
Grunt nunjucks-2-html
我正在尝试通过 g运行t nunjucks-2-html:
编译我的模板
这是我的简化 g运行t 文件:
module.exports = function(grunt) {
grunt.initConfig({
nunjucks: {
options: {
data: {},
paths: '/templates/'
},
render: {
files: [
{
expand: true,
src: '*.html',
cwd: '/templates',
dest: 'build',
ext: '.html'
}
]
}
}
});
grunt.loadNpmTasks('grunt-nunjucks-2-html');
};
我的文件夹结构如下所示:
```
project
│ Gruntfile.js
│
└───templates
│ index.html
│ foo.html
│
└───build
```
当我 运行 g运行t nunjucks 我得到以下错误:
"Running "nunjucks:render" (nunjucks) 任务未指定文件。"
所以很明显nunjucks找不到我的模板。
我不知道在哪里配置模板路径,对我来说我的 g运行tfile 似乎有效。如果你有什么想法,我会很高兴。
谢谢!
__dirname
变量引用 Gruntfile 所在的目录。
您可以尝试使用 paths: __dirname + '/templates/'
或只是 paths: 'templates'
,如 nunjucks-2-html npm documentation 中所述。
我正在尝试通过 g运行t nunjucks-2-html:
编译我的模板这是我的简化 g运行t 文件:
module.exports = function(grunt) {
grunt.initConfig({
nunjucks: {
options: {
data: {},
paths: '/templates/'
},
render: {
files: [
{
expand: true,
src: '*.html',
cwd: '/templates',
dest: 'build',
ext: '.html'
}
]
}
}
});
grunt.loadNpmTasks('grunt-nunjucks-2-html');
};
我的文件夹结构如下所示:
```
project
│ Gruntfile.js
│
└───templates
│ index.html
│ foo.html
│
└───build
```
当我 运行 g运行t nunjucks 我得到以下错误:
"Running "nunjucks:render" (nunjucks) 任务未指定文件。" 所以很明显nunjucks找不到我的模板。 我不知道在哪里配置模板路径,对我来说我的 g运行tfile 似乎有效。如果你有什么想法,我会很高兴。
谢谢!
__dirname
变量引用 Gruntfile 所在的目录。
您可以尝试使用 paths: __dirname + '/templates/'
或只是 paths: 'templates'
,如 nunjucks-2-html npm documentation 中所述。