I have a simple JavaScript project that uses Babel to forward ECMAScript 6 to ES5, and then requires Browserify to use ES6 modules.
So, I came up with this Gruntfile.jsone to compile it:
module.exports = function(grunt) {
"use strict";
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-browserify');
grunt.initConfig({
"babel": {
options: {
sourceMap: true
},
dist: {
files: {
"lib/pentagine.js": "lib/pentagine_babel.js",
"demos/helicopter_game/PlayState.js": "demos/helicopter_game/PlayState_babel.js"
}
}
},
"browserify": {
dist: {
files: {
"lib/pentagine.js": "lib/pentagine_babel.js",
"demos/helicopter_game/PlayState.js": "demos/helicopter_game/PlayState_babel.js"
}
}
}
});
grunt.registerTask("default", ["babel", "browserify"]);
};
gruntworks fine, no errors. However, I get the following errors:
Uncaught SyntaxError: Unexpected reserved wordon export
Uncaught SyntaxError: Unexpected reserved wordonimport
Basically what I do in the main file is the following:
export class Game {
...
}
And then import it as:
import {Sprite, Game} from "lib/pentagine";
I do all the code in accordance with ECMAScript 6. However, the export / import does not work and instead encounters JavaScript reserved words (despite the fact that it works for me browserify.js).