Skip to content

Latest commit

 

History

History
53 lines (36 loc) · 1.27 KB

es6.md

File metadata and controls

53 lines (36 loc) · 1.27 KB

ES6

Babel

Webpacker ships with babel - a JavaScript compiler so you can use next generation JavaScript, today. The Webpacker installer sets up a standard .babelrc file in your app root, which will work great in most cases because of babel-env-preset.

Following ES6/7 features are supported out of the box:

  • Async/await.
  • Object Rest/Spread Properties.
  • Exponentiation Operator.
  • Dynamic import() - useful for route level code-splitting
  • Class Fields and Static Properties.

We have also included babel polyfill that includes a custom regenerator runtime and core-js.

Don't forget to import babel-polyfill in your main entry point like so:

import "babel-polyfill"

Module import() vs require()

While you are free to use require() and module.exports, we encourage you to use import and export instead since it reads and looks much better.

import Button from 'react-bootstrap/lib/Button'

// or
import { Button } from 'react-bootstrap'

class Foo {
  // code...
}

export default Foo
import Foo from './foo'

You can also use named export and import

export const foo = () => console.log('hello world')
import { foo } from './foo'