javascript - Experimenting with babeljs+amd getting undefined for module -


i'm experimenting babel.js alongside requirejs. require given, can't drop sadly :( found in babeljs docs there's --modules amd cli flag transpiles es6 code amd defines. far good. made quick example "application" test out. here's structure:

. |-- build.sh |-- index.html |-- js |   |-- assets |   |   |-- asseta.es6 |   |   |-- asseta.js |   |   |-- bootstrap.es6 |   |   `-- bootstrap.js |   `-- main.js `-- node_modules 

index.html

<body>     <p>hello world! html5 boilerplate.</p>     <script type="text/javascript" src="node_modules/requirejs/require.js" data-main="js/main.js"></script> </body> 

main.js

(function() {   require.config({     baseurl: "js/assets"   });   require(["bootstrap"], function(bootstrap) {     bootstrap.ready(function(sum) {       console.log(sum(1,2,3));     });   }); }()); 

bootstrap.es6

import asseta 'asseta';  console.log(asseta); // undefined :((  export function ready(cb) {   cb(asseta.sum); } 

asseta.es6

export function sum(...nums) {   return nums.reduce(((acc, num) => acc += num), 0); } 

my problem application main.js loads bootstrap properly, if log out got existing object ready function in -> ok bootstrap module can't load asseta module properly. undefined :(

what missing?

additional info

the build.sh script transpiles .es6 files es5 .js

#!/bin/sh  babel --modules amd js/assets/bootstrap.es6 -o js/assets/bootstrap.js babel --modules amd js/assets/asseta.es6 -o js/assets/asseta.js 

it user error. missed default keyword in asseta.es6 like

export default function sum(...nums) {   return nums.reduce(((acc, num) => acc += num), 0); } 

or other approach fix omit default keyword asseta refactor bootstrap as

import { sum } 'asseta'; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -