Install  Babel 6 related packages:

npm install --save-dev babel-register

npm install --save-dev babel-plugin-add-module-exports

npm uninstall --save-dev babel-core
npm install --save-dev babel-core

npm install babel-preset-es2015

Create .babelrc file:
vi .babelrc

{
"presets": ["es2015"],
"plugins": ["babel-plugin-add-module-exports"]
}

Chanage server/index.js file:
vi server/index.js

if (env === 'development' || env === 'test') {
// Register the Babel require hook
//require('babel-core/register');
require('babel-register');
}

Change Gruntfile.js file:

// Compiles ES6 to JavaScript using Babel
babel: {
options: {
sourceMap: true,
babelrc: true,
//presets: ['es2015'],
//plugins: ["babel-plugin-add-module-exports"]
},
client: {
files: [{
expand: true,
cwd: '<%= yeoman.client %>',
src: ['{app,components}/**/!(*.spec).js'],
dest: '.tmp'
}]
},
server: {
files: [{
expand: true,
cwd: '<%= yeoman.server %>',
src: ['**/*.{js,json}'],
dest: '<%= yeoman.dist %>/<%= yeoman.server %>'
}]
}
},
...

Test:

grunt serve
grunt build

Babel 6 Options

babel-plugin-add-module-exports

Leave a Reply