Preparing Your JavaScript Files for ES2015

To use the ES2015 syntax in a JavaScript file, add the extension .es to its name. For example, you rename file filename.js to filename.es.js. The extension indicates it uses ES2015 syntax and must therefore be transpiled by Babel before deployment.

ES2015 advanced features, such as generators, are available to you if you import the polyfillBabel class from the polyfill-babel module found in Liferay Portal CE 7.0:

import polyfillBabel from 'polyfill-babel'

The Babel Polyfill emulates a complete ES6 environment. Use it at your own discretion, as it loads a large amount of code. You can inspect https://github.com/zloirock/core-js#core-js to see what’s polyfilled.

Once you’ve completed writing your module, you can expose it by creating a package.json file that specifies your bundle’s name and version. Make sure to create this in your module’s root folder. The js-logger module, for example, specifies the following values in its package.json file:

{
    "name": "js-logger",
    "version": "1.0.0"
}

The Module Config Generator creates the module based on this information. There you have it! In just a few steps you can prepare your module to leverage the latest JavaScript standard features and publish it.

Related Topics

Using ES2015 Modules in Your Portlet

OSGi and Modularity for Liferay Portal 6 Developers

0 (0 Votes)
Using ES2015 in Your Portlets Previous