javascript - Use Babel Generated AMD Modules -


i have existing app amd modules based , use require.js on bundling things. need bring bunch of es2015 react code app amd modules , use babel turn them amd modules. here babel config

 babel:   options:     sourcemap: false     plugins: [ 'transform-class-properties',                 'transform-object-rest-spread',                 'transform-es2015-modules-amd']     presets: [ 'react','es2015']   dist:      files: [{       expand: true       cwd: "src/foo/jsx"       src: "**/*.js"       dest: "build/foo/js/"       ext: ".js"       }]  

the result works , generates amd modules follows instance myreact.js module:

define(["exports", "react", "prop-types"], function (exports, _react, _proptypes) {   "use strict";   object.defineproperty(exports, "__esmodule", {     value: true   });   var _react2 = _interoprequiredefault(_react);   var _proptypes2 = _interoprequiredefault(_proptypes);   function _interoprequiredefault(obj) {     return obj && obj.__esmodule ? obj : {       default: obj     };   }   var required_field_symbol = "*";   function blah(props) {     ...   }   exports.default = blah; }); 

now, when use amd module in other amd modules define, undefined

define([..., 'foo/js/myreact'], function(..., rm) {  rm.blah <---- undefied rm.default <---- still undefied 

the generated code not return exports.

also, noticed in require.js generated bundle.js, react model shows follows:

define('foo/js/myreact',["exports", "react", "prop-types"],     function (exports, _react, _proptypes){ .. } 

i not defining exports anywhere in require.js config file how supposed setup exports?

basically, how should use react amd modules within other amd modules?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -