2

I'm writing ES6 and using babel to generate my Yeoman generators. The problem comes in that after compiling to es5 the rendered file needs me to touch it up.

Basic generator es6 file

'use strict'
import { NamedBase } from 'yeoman-generator'

export default class MyGenerator extends NamedBase {
  generateComponent () {
    console.log('Name passed - ' + this.name))
  }
}

after compiling

I then need to go into the generated file and change the last line from exports.default = MyGenerator; to module.exports = MyGenerator; to make it work.

What am I missing?

REF: my current repo: https://github.com/GantMan/irrigate/tree/7a897d4669e479cdd7b5509b1807e0b26d5c6658

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Gant Laborde
  • 6,484
  • 1
  • 21
  • 30
  • Possible duplicate of [Babel 6 changes how it exports default](http://stackoverflow.com/questions/33505992/babel-6-changes-how-it-exports-default) – Bergi Nov 16 '15 at 22:09

2 Answers2

1

This is due to a Babel 6 change.

You can use this plugin to get the old export behavior.

Might also be worth discussing with the Babel community. This change is pretty major.

Simon Boudrias
  • 42,953
  • 16
  • 99
  • 134
0

Even though Simon's post is very helpful on identifying the reason, it didn't work as a solution. I finally conceded that any ES5 JS would simply pass through the compiler and therefore I could force my last line to be module.exports = ScreenGenerator by leaving it in my source.

I guess the TL:DR; - If there's 1 small part that's not compiling as you want, the quick fix is to write that 1 part as you want it compiled.

Gant Laborde
  • 6,484
  • 1
  • 21
  • 30