yeoman在模板中打印代码字符

时间:2016-05-09 01:37:35

标签: yeoman yeoman-generator

当我用this.copyTpl复制模板时,yeoman打印代码cacharter的引号而不是引号......这里我在做什么 在index.js

this.dependencies["fontawesome"] = "4.2";
this.dependencies["jQuery"] = "~1.11.1";
this.dependencies["responsive-nav"] = "1.0.34";
this.dependencies["superfish"] = "1.7.5";

this.dep = JSON.stringify(this.dependencies); 

console.log(this.dep)
display 
{"fontawesome":"4.2","jQuery":"~1.11.1","responsive-nav":"1.0.34","superfish":"1.7.5"}

 this.fs.copyTpl(
            this.templatePath('_bower.json'),
            this.destinationPath(projectPath +'/bower.json'),{
                projectName: _.slugify(this.project_name),
                dependencies: this.dep
            }
        );

结果文件

{"fontawesome":"4.2","jQuery":"~1.11.1","responsive-nav":"1.0.34","superfish":"1.7.5"},

为什么会发生这种情况,我需要额外的配置?我错过了什么?谢谢你的帮助

1 个答案:

答案 0 :(得分:11)

<%=传递给它的转义值以防止XSS。

要输出原始输入,您需要使用<%-模板标记。

Yeoman在http://ejs.co/

使用的模板引擎的完整文档