我正在jadeify
使用browserify
在我的前端使用jade模板。
Gulp Setup
gulp.task('browserify', function () {
var bundler = browserify({entries: ['./frontend/js/app.js']});
var bundle = function () {
return bundler
.transform(jadeify)
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./public/js'))
};
if (global.isWatching) {
bundler = watchify(bundler);
bundler.on('update', bundle);
}
return bundle();
});
玉石文件
.header
h1 Login
.content
div
input(placeholder="Username", name="uname", type="text")
input(placeholder="Password", name="pword", type="password")
.footer
a(href="/signup")
span Create an Account
要求使用玉文件
require('../../views/index.jade')({jamie:'hello'})
app.js内的输出
module.exports = function template(locals) {
var buf = [];
var jade_mixins = {};
var jade_interp;
buf.push("<div class=\"header\"><h1>Login</h1></div><div class=\"content\"><div><input placeholder=\"Username\" name=\"uname\" type=\"text\"/><input placeholder=\"Password\" name=\"pword\" type=\"password\"/></div></div><div class=\"footer\"><a href=\"/signup\"><span>Create an Account</span></a></div>");;return buf.join(""); };
一切都很好
更改jade文件中的任何内容时gulp出错
[14:36:14] gulp-notify: [Compile Error] C:\var\www\mywarhammer.co.uk\frontend\views\index.jade:8
6| var jade_interp;
7|
> 8| buf.push("<div class=\"header\"><h1>Login</h1></div><div class=\"content\"><div><input placeholder=\"Username\" name=\"uname\" the an Account</span></a></div>");;return buf.join("");
9| };
Unexpected character h expected ` `, `\n`, `,`, `!` or `=` while parsing file: C:\var\www\mywarhammer.co.uk\frontend\views\index.jade
我怎样才能阻止这种打破?
修改
此后我从gulp-notify中添加了更多关于这些错误的输出......他们实际上并没有给我很多帮助。在我看来,它们来自原始的jade
文件:/
Unexpected character h expected ` `, `\n`, `,`, `!` or `=` while parsing file: C:\var\www\mywarhammer.co.uk\frontend\views\home.jade
[ { [Error: C:\var\www\mywarhammer.co.uk\frontend\views\home.jade:8
6| var jade_interp;
7|
> 8| buf.push("<div class=\"header\"><h1>Login</h1></div><div class=\"content\"><div><input placeholder=\"Username\" name=\"uname\" type=\"text\"/>
ate an Account " + (jade.escape((jade_interp = locals.jamie) == null ? '' : jade_interp)) + "</span></a></div>");;return buf.join("");
9| };
Unexpected character h expected ` `, `\n`, `,`, `!` or `=` while parsing file: C:\var\www\mywarhammer.co.uk\frontend\views\home.jade]
path: 'C:\\var\\www\\mywarhammer.co.uk\\frontend\\views\\home.jade',
filename: 'C:\\var\\www\\mywarhammer.co.uk\\frontend\\views\\home.jade',
stream:
{ _readableState: [Object],
readable: true,
domain: null,
_events: [Object],
_maxListeners: 10,
_writableState: [Object],
writable: true,
allowHalfOpen: true,
_options: [Object],
_wrapOptions: [Object],
_streams: [Object],
length: 1,
label: 'deps' } } ]
答案 0 :(得分:1)
尝试更改
中的转义引号 buf.push("<div class=\"header\"><h1>Login</h1></div><div class=\"content\"><div><input placeholder=\"Username\" name=\"uname\" type=\"text\"/><input placeholder=\"Password\" name=\"pword\" type=\"password\"/></div></div><div class=\"footer\"><a href=\"/signup\"><span>Create an Account</span></a></div>");
到
buf.push("<div class='header'><h1>Login</h1></div><div class='content'><div><input placeholder='Username' name='uname' type='text'/><input placeholder='Password' name='pword' type='password'/></div></div><div class='footer'><a href='/signup'><span>Create an Account</span></a></div>");
因为字符串可能通过两个不同的解析器 - 第一个将\"
解释为"
,第二个解析混淆。