Use aliasify everywhere instead of browserify-global-shim (#7476)
I already had to aliasify to have better control over the requires so we might as well do it everywhere for consistency. This probably makes it easier to rebase the rollup work too because aliases seems to be how you solve this in that world.
Sebastian Markbåge committed
Aug 11, 2016 at 20:17 UTC
c8f7215b200e37f1679da2bebfc2b68876fb15a3
6 files changed
+62
-32
grunt/config/browserify.js
+9
-30
@@ -8,39 +8,18 @@ var UglifyJS = require('uglify-js');
8
var uglifyify = require('uglifyify');
9
var derequire = require('derequire');
10
var aliasify = require('aliasify');
11
-var globalShim = require('browserify-global-shim');
11
var collapser = require('bundle-collapser/plugin');
12
13
var envifyDev = envify({NODE_ENV: process.env.NODE_ENV || 'development'});
14
var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'});
15
17
-var SECRET_INTERNALS_NAME = 'React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED';
18
-
19
-var shimSharedModulesFiles = {
20
- './ReactCurrentOwner': SECRET_INTERNALS_NAME + '.ReactCurrentOwner',
21
- './ReactComponentTreeHook': SECRET_INTERNALS_NAME + '.ReactComponentTreeHook',
22
- // Use the global, anywhere we require React
23
- './React': 'React',
24
-};
25
-
26
-// We can access these as absolute or relative. We need to shim both.
27
-for (var key in shimSharedModulesFiles) {
28
- shimSharedModulesFiles[key.replace(/^\.\//, 'react/lib/')] = shimSharedModulesFiles[key];
29
-}
30
-
31
-var shimSharedModules = globalShim.configure(shimSharedModulesFiles);
32
-
33
-// Fiber needs the symbol from ReactElement right now. So we can't shim
34
-// ReactElement. Otherwise this would just be the same as above.
35
-// TODO: Refactor this so that Fiber can access the symbol without bringing in
36
-// the rest of ReactElement.
37
-var shimSharedModulesFiberFiles = {};
38
-for (var key in shimSharedModulesFiles) {
39
- if (!/ReactElement/.test(key)) {
40
- shimSharedModulesFiberFiles[key] = shimSharedModulesFiles[key];
41
- }
42
-}
43
-var shimSharedModulesFiber = globalShim.configure(shimSharedModulesFiberFiles);
16
+var shimSharedModules = aliasify.configure({
17
+ 'aliases': {
18
+ 'react/lib/React': 'react/lib/ReactUMDShim',
19
+ 'react/lib/ReactCurrentOwner': 'react/lib/ReactCurrentOwnerUMDShim',
20
+ 'react/lib/ReactComponentTreeHook': 'react/lib/ReactComponentTreeHookUMDShim',
21
+ },
22
+});
23
24
var shimDOMModules = aliasify.configure({
25
'aliases': {
@@ -219,7 +198,7 @@ var domFiber = {
198
debug: false,
199
standalone: 'ReactDOMFiber',
200
// Apply as global transform so that we also envify fbjs and any other deps
222
- transforms: [shimSharedModulesFiber],
201
+ transforms: [shimSharedModules],
202
globalTransforms: [envifyDev],
203
plugins: [collapser],
204
after: [derequire, simpleBannerify],
@@ -234,7 +213,7 @@ var domFiberMin = {
213
standalone: 'ReactDOMFiber',
214
// Envify twice. The first ensures that when we uglifyify, we have the right
215
// conditions to exclude requires. The global transform runs on deps.
237
- transforms: [shimSharedModulesFiber, envifyProd, uglifyify],
216
+ transforms: [shimSharedModules, envifyProd, uglifyify],
217
globalTransforms: [envifyProd],
218
plugins: [collapser],
219
// No need to derequire because the minifier will mangle
gulpfile.js
+1
-1
@@ -31,7 +31,7 @@ var paths = {
31
src: [
32
'src/umd/ReactUMDEntry.js',
33
'src/umd/ReactWithAddonsUMDEntry.js',
34
- 'src/umd/shims/ReactAddonsDOMDependenciesUMDShim.js',
34
+ 'src/umd/shims/**/*.js',
35
36
'src/isomorphic/**/*.js',
37
'src/addons/**/*.js',
package.json
-1
@@ -34,7 +34,6 @@
34
"babel-traverse": "^6.9.0",
35
"babylon": "6.8.0",
36
"browserify": "^13.0.0",
37
- "browserify-global-shim": "^1.0.3",
37
"bundle-collapser": "^1.1.1",
38
"coffee-script": "^1.8.0",
39
"core-js": "^2.2.1",
src/umd/shims/ReactComponentTreeHookUMDShim.js
new
+18
@@ -0,0 +1,18 @@
1
+/**
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule ReactComponentTreeHookUMDShim
10
+ */
11
+
12
+/* globals React */
13
+
14
+'use strict';
15
+
16
+var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
17
+
18
+module.exports = ReactInternals.ReactComponentTreeHook;
src/umd/shims/ReactCurrentOwnerUMDShim.js
new
+18
@@ -0,0 +1,18 @@
1
+/**
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule ReactCurrentOwnerUMDShim
10
+ */
11
+
12
+/* globals React */
13
+
14
+'use strict';
15
+
16
+var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
17
+
18
+module.exports = ReactInternals.ReactCurrentOwner;
src/umd/shims/ReactUMDShim.js
new
+16
@@ -0,0 +1,16 @@
1
+/**
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule ReactUMDShim
10
+ */
11
+
12
+/* globals React */
13
+
14
+'use strict';
15
+
16
+module.exports = React;