React: Requiring react-addons-css-transition-group includes React in webpack builds that exclude react

Created on 25 Mar 2016  路  6Comments  路  Source: facebook/react

I'm trying to use the addon in a layout component with react and react-dom as peer dependencies, but if I include it my build goes from 55k to 750k.

The published npm module is simply this line of code:
module.exports = require('react/lib/ReactTransitionGroup');

If I look at react/lib/ReactTransitionGroup, I see this line
var React = require('./React');

Which causes webpack to pull in all of react, since I only defined 'react' as an external module

I could make 'react-addons-css-transition-group' external to my webpack build, but there's no distributed script for just that addon that adds it to the window variable (similar to how including the react script adds window.React and react-dom adds window.ReactDOM)

The timeout-transition-group module depends on react-addons-css-transition-group so it has the same problem

Most helpful comment

OK, this works (I didn't know webpack supported it)

externals: {
    'react': { commonjs: 'react', commonjs2: 'react', amd: 'react', root: 'React' },
    'react-dom': { commonjs: 'react-dom', commonjs2: 'react-dom', amd: 'react-dom', root: 'ReactDOM' },
    'react-addons-css-transition-group': { commonjs: 'react-addons-css-transition-group', commonjs2: 'react-addons-css-transition-group', amd: 'react-addons-css-transition-group', root: ['React','addons','CSSTransitionGroup'] }
  }

Produces:

 factory(root["React"], root["React"]["addons"]["CSSTransitionGroup"], root["ReactDOM"])

Thanks

All 6 comments

Yes, these modules only work when packaged with the react module from npm (it does this because we need access to private APIs). If you want to use the prepackaged React and an addon, then we recommend use use ReactWithAddons and map react-addons-css-transition-group to React.addons.CSSTransitionGroup.

OK, this works (I didn't know webpack supported it)

externals: {
    'react': { commonjs: 'react', commonjs2: 'react', amd: 'react', root: 'React' },
    'react-dom': { commonjs: 'react-dom', commonjs2: 'react-dom', amd: 'react-dom', root: 'ReactDOM' },
    'react-addons-css-transition-group': { commonjs: 'react-addons-css-transition-group', commonjs2: 'react-addons-css-transition-group', amd: 'react-addons-css-transition-group', root: ['React','addons','CSSTransitionGroup'] }
  }

Produces:

 factory(root["React"], root["React"]["addons"]["CSSTransitionGroup"], root["ReactDOM"])

Thanks

EDIT: removed to avoid confusion

EDIT: removed to avoid confusion

I鈥檓 confused about what you鈥檙e trying to do. If you just want to exclude react from your build of a library that depends on react-transition-group (the standalone version), you just need to put react in your externals. This should be enough.

If you have any issues with standalone react-transition-group please file issues in https://github.com/reactjs/react-transition-group and you鈥檒l get the answers there. Posting in this thread makes it very confusing because react-addons-transition-group (which this thread is about) had a completely different internal structure, which is why no information from this thread is relevant now.

Putting them together in comments like https://github.com/facebook/react/issues/6343#issuecomment-298412112 will just further confuse future readers, as there is no relation between the two, except one is the fork of the other.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabegreenberg picture gabegreenberg  路  119Comments

addyosmani picture addyosmani  路  143Comments

gaearon picture gaearon  路  126Comments

wohali picture wohali  路  128Comments

sebmarkbage picture sebmarkbage  路  136Comments