I hope someone can help.
I'm using grunt-babel to convert my ES6 module code to ES5 AMD module code. Here's my ES6 code:
multiply.js
export default function (x,y) {
return x * y;
};
square.js
import multiply from 'multiply';
export default function (x) {
return multiply(x,x);
};
app.js
import square from 'square';
var myValue = square(2);
console.log(myValue);
As you can see, all I'm doing is creating a module 'multiply', importing that into another module 'square', and then finally using 'square' in my main js file. The above 3 files then gets converted to the following:
multiply.js
define("multiply", ["exports", "module"], function (exports, module) {
module.exports = function (x, y) {
return x * y;
};
});
square.js
define("square", ["exports", "module", "multiply"], function (exports, module, _resourcesJsEs6moduleExampleMultiply) {
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var multiply = _interopRequire(_resourcesJsEs6moduleExampleMultiply);
module.exports = function (x) {
return multiply(x, x);
};
});
app.js
define("app", ["exports", "square"], function (exports, _resourcesJsEs6moduleExampleSquare) {
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var square = _interopRequire(_resourcesJsEs6moduleExampleSquare);
var myValue = square(2);
console.log(myValue);
});
The problem I have is that I expected the 'app.js' file to be converted to something more like this:
requirejs(['square'],
function (square) {
var myValue = square(2);
console.log(myValue);
}
);
In my gruntfile.js my config is pretty simple:
options: {
moduleIds: true,
modules: 'amd',
blacklist: ['strict']
}
Am I doing something wrong?