我正在做一个dojo项目(1.11.x),最近开始使用ES6(ES 2015)语法,比如const、let和template文字。在我使用dojo-util构建项目之前,它一直工作得很好。我遇到了如下错误
ERROR - Parse error. TypeError: redeclaration of const {variable name}
ERROR - Parse error. illegal character
return `<a href="/xxx/xxx/${a}">${b}</a>`;
^
有没有办法让构建系统识别ES6语法或者绕过语法检查?
2条答案
按热度按时间kcugc4gi1#
2016年12月发布的最新Dojo 1.12版本已更新为使用支持ES6到ES5转换的闭包编译器20160911。
我在一个项目中有旧的ES5模块和新的ES6模块。
在ES6模块中,必须在开头添加 “use strict”,否则构建失败。
app/es6/Dialog.js
然后在app.profile.js中添加 optimizeOptions 对象
app/Main.js
通过这种方式,您可以将ES6集成到当前的Dojo项目中。
我还试图通过设置 languageOut来避免在ES6模块中“使用strict”:ECMASCRIPT5_STRICT 与mention here相同,但它会破坏Dojo本身。
xdnvmnnf2#
由于Dojo 1.x上的开发似乎已经停滞,并且无法轻松迁移到Dojo 2.x,我们不得不想出一个解决方案。作为开发人员,我们之所以停留在ES 5特性上,仅仅是因为构建过程无法处理它,这是越来越荒谬的。
这就是为什么我想出了一个解决方案,目前正在我们公司测试。对于感兴趣的人,这是我们如何解决这个问题(仍然使用Dojo构建过程的核心部分):
这仍然是实验性的,但第一个结果看起来很好,似乎没有回归。