反应路由器 Link 参数。意外字符“`”。在丑化和 eslint 中

React Router Link params. Unexpected character '`'. in uglify and eslint

我在同时使用 gulp uglify 和 eslint 时遇到意外字符 '`'。

<td><Link to={`/user/${u.userId}`}>{u.UserName}</Link></td>

在 gulp 文件中

Gulp.task('js', function(){
    Browserify(GulpConfig.paths.mainJs, { debug: (production() ? false : true)})
        .transform(Reactify)
        .bundle()
        .on('error', console.error.bind(console))
        .pipe(Source('bundle.js'))
        .pipe(production(Buffer()))
        .pipe(production(Uglify().on('error', gulpUtil.log)))
        .pipe(Gulp.dest(GulpConfig.paths.dist + '/scripts'))
        .pipe(Connect.reload());
});

如何处理?

使用 ES6 模板字符串需要您通过 Babel 之类的工具转译您的代码,您目前没有这样做。

但是,由于您使用的是 reactify,因此您可以添加选项 {"es6": true} 以参与某些 ES6 功能,例如箭头函数或模板字符串。

.transform(Reactify, {es6: true})

reactify目前支持的entire feature set有箭头函数、rest参数、模板、对象简写和类.

如果您打算长期使用 React 和 ES6,我当然建议您使用 Babel 作为您的一站式商店,而不是使用 browserify、reactify 做所有的爵士乐,这两个都是很棒的工具和过去对我帮助很大。