Die neueste Version von Dojo 1.12 vom Dezember 2016 wurde aktualisiert, um den Closure Compiler 20160911 zu verwenden, der das Umsetzen von ES6 auf ES5 unterstützt.
Ich habe in einem Projekt ältere ES5-Module und neue in ES6.
In ES6-Modulen müssen Sie am Anfang "use strict" hinzufügen, sonst schlägt das Gebäude fehl.
error(307) Failed to evaluate module tagged as pure AMD
(fell back to processing with regular expressions). module: app/es6/Test;
error: SyntaxError: Block-scoped declarations (let, const, function, class)
not yet supported outside strict mode
app/es6/Dialog.js
"use strict"
define(["dijit/ConfirmDialog"], (ConfirmDialog) => {
let id = '1'
const dialog = new ConfirmDialog({
title: "Delete",
content: `Are you sure you want to delete ${id} ?`,
style: "width: 300px"
})
dialog.show()
})
Dann in Ihrem app.profile.js optimizeOptions Objekt
...
optimizeOptions: {
languageIn: 'ECMASCRIPT6',
languageOut: 'ECMASCRIPT5'
},
layerOptimize: "closure.keeplines",
optimize: "closure.keeplines",
cssOptimize: "comments",
mini: true,
stripConsole: "all",
selectorEngine: "lite",
useSourceMaps: false,
...
layers: {
"dojo/dojo": {
includeLocales: [ 'en-us' ],
include: [ "dojo/dojo", "dojo/hash" ],
boot: true,
customBase: true
}
"app/Main": {
includeLocales: [ 'en-us' ],
include: [
'app/Header',
'app/Main'
]
},
...
app/main.js
define(["app/es6/Dialog"], function(Dialog) {
Dialog.show();
});
hinzufügen
Auf diese Weise können Sie ES6 in Ihr aktuelles Dojo-Projekt integrieren.
versuchte ich auch, indem languageOut "use strict" in ES6 Modulen zu vermeiden: ECMASCRIPT5_STRICT als mention here aber es bricht Dojo selbst.
Ich nehme an, Sie erwarten, dass Ihr Code nur auf einem Browser läuft, der ES6 unterstützt (also kein IE10 zum Beispiel)? Andernfalls müssen Sie Ihr ES6 zuerst in ES5 umwandeln, und es löst Ihr Problem – ben
BTW, ich denke, das Problem liegt an der Optimierung (shrinksafe, closure oder uglifyjs) – ben