requirejs-es2015
v1.0.2
Published
RequireJS plugin to load ES2015 modules via babel.
Downloads
15
Keywords
Readme
requirejs-es2015
A RequireJS plugin to load ECMAScript 2015 modules via babel. It depends on babel-core 6.x and comes with the ES2015 preset as well as babel plugin for transforming ES2015 modules to AMD.
For transforming advanced ECMAScript syntax, it uses your projects .babelrc
, so you can
choose, which presets and plugins you want to use.
Table of contents
Features
- Transpile ES2015 modules to AMD RequireJS modules and load them via
es!
prefix - ESNext support using your very own
.babelrc
or babel-config from yourpackage.json
Installation
Install the package either by using npm or yarn.
npm i -D requirejs-es2015
yarn add -D requirejs-es2015
Usage
To make use of the plugin, you want to modify your RequireJS config file, to contain the path to the requirejs-es2015 package as well as an optional file extension that is used by your ES2015 files.
It should look something like this:
requirejs.config({
// ...
paths: {
es: 'node_modules/requirejs-es2015/es'
},
babel: {
fileExtension: '.js' // extension of your ES2015 files - defaults to .js
}
// ...
});
You can now import ES2015 modules in your RequireJS files like this:
define([
'es!myModule',
'es!components/anotherModule'
], function(myModule, anotherModule) {
myModule.method();
anotherModule.test();
});
If you want to use babel-transformations besides the built-in ES2015 preset, you can create a .babelrc
in your projects root directory (if not already present) or use the babel
section of your package.json
file.
Todo
- [ ] Add examples
- [ ] Add module exports for
export default
syntax
License
MIT