Skip to content
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

Use aliasify everywhere instead of browserify-global-shim #7476

Merged
merged 1 commit into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 9 additions & 30 deletions grunt/config/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,18 @@ 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 shimSharedModulesFiles = {
'./ReactCurrentOwner': SECRET_INTERNALS_NAME + '.ReactCurrentOwner',
'./ReactComponentTreeHook': SECRET_INTERNALS_NAME + '.ReactComponentTreeHook',
// Use the global, anywhere we require React
'./React': 'React',
};

// We can access these as absolute or relative. We need to shim both.
for (var key in shimSharedModulesFiles) {
shimSharedModulesFiles[key.replace(/^\.\//, 'react/lib/')] = shimSharedModulesFiles[key];
}

var shimSharedModules = globalShim.configure(shimSharedModulesFiles);

// Fiber needs the symbol from ReactElement right now. So we can't shim
// ReactElement. Otherwise this would just be the same as above.
// TODO: Refactor this so that Fiber can access the symbol without bringing in
// the rest of ReactElement.
var shimSharedModulesFiberFiles = {};
for (var key in shimSharedModulesFiles) {
if (!/ReactElement/.test(key)) {
shimSharedModulesFiberFiles[key] = shimSharedModulesFiles[key];
}
}
var shimSharedModulesFiber = globalShim.configure(shimSharedModulesFiberFiles);
var shimSharedModules = aliasify.configure({
'aliases': {
'react/lib/React': 'react/lib/ReactUMDShim',
'react/lib/ReactCurrentOwner': 'react/lib/ReactCurrentOwnerUMDShim',
'react/lib/ReactComponentTreeHook': 'react/lib/ReactComponentTreeHookUMDShim',
},
});

var shimDOMModules = aliasify.configure({
'aliases': {
Expand Down Expand Up @@ -219,7 +198,7 @@ var domFiber = {
debug: false,
standalone: 'ReactDOMFiber',
// Apply as global transform so that we also envify fbjs and any other deps
transforms: [shimSharedModulesFiber],
transforms: [shimSharedModules],
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, simpleBannerify],
Expand All @@ -234,7 +213,7 @@ var domFiberMin = {
standalone: 'ReactDOMFiber',
// Envify twice. The first ensures that when we uglifyify, we have the right
// conditions to exclude requires. The global transform runs on deps.
transforms: [shimSharedModulesFiber, envifyProd, uglifyify],
transforms: [shimSharedModules, envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var paths = {
src: [
'src/umd/ReactUMDEntry.js',
'src/umd/ReactWithAddonsUMDEntry.js',
'src/umd/shims/ReactAddonsDOMDependenciesUMDShim.js',
'src/umd/shims/**/*.js',

'src/isomorphic/**/*.js',
'src/addons/**/*.js',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"babel-traverse": "^6.9.0",
"babylon": "6.8.0",
"browserify": "^13.0.0",
"browserify-global-shim": "^1.0.3",
"bundle-collapser": "^1.1.1",
"coffee-script": "^1.8.0",
"core-js": "^2.2.1",
Expand Down
18 changes: 18 additions & 0 deletions src/umd/shims/ReactComponentTreeHookUMDShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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 ReactComponentTreeHookUMDShim
*/

/* globals React */

'use strict';

var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

module.exports = ReactInternals.ReactComponentTreeHook;
18 changes: 18 additions & 0 deletions src/umd/shims/ReactCurrentOwnerUMDShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 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 ReactCurrentOwnerUMDShim
*/

/* globals React */

'use strict';

var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

module.exports = ReactInternals.ReactCurrentOwner;
16 changes: 16 additions & 0 deletions src/umd/shims/ReactUMDShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 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 ReactUMDShim
*/

/* globals React */

'use strict';

module.exports = React;