-
Notifications
You must be signed in to change notification settings - Fork 47.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bundle DOM renderers into their individual UMD bundles #7164
Changes from all commits
693bbe2
61adf43
8fd6831
948c5d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,30 @@ var grunt = require('grunt'); | |
var UglifyJS = require('uglify-js'); | ||
var uglifyify = require('uglifyify'); | ||
var derequire = require('derequire'); | ||
var aliasify = require('aliasify'); | ||
var globalShim = require('browserify-global-shim'); | ||
var collapser = require('bundle-collapser/plugin'); | ||
|
||
var envifyDev = envify({NODE_ENV: process.env.NODE_ENV || 'development'}); | ||
var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'}); | ||
|
||
var SECRET_INTERNALS_NAME = 'React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'; | ||
|
||
var shimSharedModules = globalShim.configure({ | ||
'./ReactCurrentOwner': SECRET_INTERNALS_NAME + '.ReactCurrentOwner', | ||
'./ReactComponentTreeHook': SECRET_INTERNALS_NAME + '.ReactComponentTreeHook', | ||
// All these methods are shared are exposed. | ||
'./ReactElement': 'React', | ||
'./ReactPropTypes': 'React.PropTypes', | ||
'./ReactChildren': 'React.Children', | ||
}); | ||
|
||
var shimDOMModules = aliasify.configure({ | ||
'aliases': { | ||
'./ReactAddonsDOMDependencies': './build/modules/ReactAddonsDOMDependenciesUMDShim.js', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is mapping to ReactAddonsDOMDependencies UMDShim , the shim file. For some reason this is how aliasify works. :) I think it is just mapping the original require path to whatever you give it which is then resolved relative to the package I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed the shim part, was asking about the RHS :) I looked at docs though - let's make that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah. neat. |
||
}, | ||
}); | ||
|
||
var SIMPLE_TEMPLATE = | ||
grunt.file.read('./grunt/data/header-template-short.txt'); | ||
|
||
|
@@ -87,6 +106,7 @@ var addons = { | |
debug: false, | ||
standalone: 'React', | ||
packageName: 'React (with addons)', | ||
transforms: [shimDOMModules], | ||
globalTransforms: [envifyDev], | ||
plugins: [collapser], | ||
after: [derequire, simpleBannerify], | ||
|
@@ -100,7 +120,72 @@ var addonsMin = { | |
debug: false, | ||
standalone: 'React', | ||
packageName: 'React (with addons)', | ||
transforms: [envifyProd, uglifyify], | ||
transforms: [shimDOMModules, envifyProd, uglifyify], | ||
globalTransforms: [envifyProd], | ||
plugins: [collapser], | ||
// No need to derequire because the minifier will mangle | ||
// the "require" calls. | ||
|
||
after: [minify, bannerify], | ||
}; | ||
|
||
// The DOM Builds | ||
var dom = { | ||
entries: [ | ||
'./build/modules/ReactDOMUMDEntry.js', | ||
], | ||
outfile: './build/react-dom.js', | ||
debug: false, | ||
standalone: 'ReactDOM', | ||
// Apply as global transform so that we also envify fbjs and any other deps | ||
transforms: [shimSharedModules], | ||
globalTransforms: [envifyDev], | ||
plugins: [collapser], | ||
after: [derequire, simpleBannerify], | ||
}; | ||
|
||
var domMin = { | ||
entries: [ | ||
'./build/modules/ReactDOMUMDEntry.js', | ||
], | ||
outfile: './build/react-dom.min.js', | ||
debug: false, | ||
standalone: 'ReactDOM', | ||
// Envify twice. The first ensures that when we uglifyify, we have the right | ||
// conditions to exclude requires. The global transform runs on deps. | ||
transforms: [shimSharedModules, envifyProd, uglifyify], | ||
globalTransforms: [envifyProd], | ||
plugins: [collapser], | ||
// No need to derequire because the minifier will mangle | ||
// the "require" calls. | ||
|
||
after: [minify, bannerify], | ||
}; | ||
|
||
var domServer = { | ||
entries: [ | ||
'./build/modules/ReactDOMServerUMDEntry.js', | ||
], | ||
outfile: './build/react-dom-server.js', | ||
debug: false, | ||
standalone: 'ReactDOMServer', | ||
// Apply as global transform so that we also envify fbjs and any other deps | ||
transforms: [shimSharedModules], | ||
globalTransforms: [envifyDev], | ||
plugins: [collapser], | ||
after: [derequire, simpleBannerify], | ||
}; | ||
|
||
var domServerMin = { | ||
entries: [ | ||
'./build/modules/ReactDOMServerUMDEntry.js', | ||
], | ||
outfile: './build/react-dom-server.min.js', | ||
debug: false, | ||
standalone: 'ReactDOMServer', | ||
// Envify twice. The first ensures that when we uglifyify, we have the right | ||
// conditions to exclude requires. The global transform runs on deps. | ||
transforms: [shimSharedModules, envifyProd, uglifyify], | ||
globalTransforms: [envifyProd], | ||
plugins: [collapser], | ||
// No need to derequire because the minifier will mangle | ||
|
@@ -114,4 +199,8 @@ module.exports = { | |
min: min, | ||
addons: addons, | ||
addonsMin: addonsMin, | ||
dom: dom, | ||
domMin: domMin, | ||
domServer: domServer, | ||
domServerMin: domServerMin, | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactAddonsDOMDependencies | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var ReactDOM = require('ReactDOM'); | ||
var ReactInstanceMap = require('ReactInstanceMap'); | ||
|
||
exports.getReactDOM = function() { | ||
return ReactDOM; | ||
}; | ||
|
||
exports.getReactInstanceMap = function() { | ||
return ReactInstanceMap; | ||
}; | ||
|
||
if (__DEV__) { | ||
var ReactPerf = require('ReactPerf'); | ||
var ReactTestUtils = require('ReactTestUtils'); | ||
|
||
exports.getReactPerf = function() { | ||
return ReactPerf; | ||
}; | ||
|
||
exports.getReactTestUtils = function() { | ||
return ReactTestUtils; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ function mountComponentIntoNode( | |
) { | ||
var markerName; | ||
if (ReactFeatureFlags.logTopLevelRenders) { | ||
var wrappedElement = wrapperInstance._currentElement.props; | ||
var wrappedElement = wrapperInstance._currentElement.props.child; | ||
var type = wrappedElement.type; | ||
markerName = 'React mount: ' + ( | ||
typeof type === 'string' ? type : | ||
|
@@ -235,8 +235,7 @@ if (__DEV__) { | |
TopLevelWrapper.displayName = 'TopLevelWrapper'; | ||
} | ||
TopLevelWrapper.prototype.render = function() { | ||
// this.props is actually a ReactElement | ||
return this.props; | ||
return this.props.child; | ||
}; | ||
|
||
/** | ||
|
@@ -421,14 +420,9 @@ var ReactMount = { | |
'for your app.' | ||
); | ||
|
||
var nextWrappedElement = ReactElement( | ||
var nextWrappedElement = ReactElement.createElement( | ||
TopLevelWrapper, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
nextElement | ||
{ child: nextElement } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break the devtools. Sorry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Time to port devtools to new APIs 😈 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we still going to break the devtools with this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't break devtools but it does start showing the top level wrapper. I switched this to an explicit flag on the wrapper type and updated devtools to support this new flag: |
||
); | ||
|
||
var nextContext; | ||
|
@@ -443,7 +437,7 @@ var ReactMount = { | |
|
||
if (prevComponent) { | ||
var prevWrappedElement = prevComponent._currentElement; | ||
var prevElement = prevWrappedElement.props; | ||
var prevElement = prevWrappedElement.props.child; | ||
if (shouldUpdateReactComponent(prevElement, nextElement)) { | ||
var publicInst = prevComponent._renderedComponent.getPublicInstance(); | ||
var updatedCallback = callback && function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix that language?