How do you manage component dependency order with Facebook React?

Let's say I have two React components, A and B, where B depends on (uses) A. Let's say A is in a.js and B is in b.js.

Is there a way in Reag to safely resolve the dependency from B to A? Thus, ensuring that no matter in what order I actually include a.js and b.js, will everything still be resolved correctly?

I believe that the Google Closure compiler effectively fakes the dependency system for you, both in development mode and in production mode. This leads to the fact that other code is not included in the source file; is there something similar for React?

+3
source share
1 answer

Note: the answer below is very outdated.

RequireJS - - , , JS .

Webpack.
, Browserify Rollup.

ES , transpiled Babel CommonJS. ES, , Rollup Webpack 2, .


, ; , - , .

RequireJS AMD sugar , :

/** @jsx React.DOM */
/* jshint trailing:false, quotmark:false, newcap:false */
define(function (require) {

  'use strict';

  var React = require('react'),
      _ = require('underscore'),
      JoinWidget = require('common/views/join_widget');

  var LoginWidget = React.createClass({
    // ...
  });
});

React, , .

, , grunt-requirejs almond, , .

+5

All Articles