Skip to content

Commit 69ab714

Browse files
committed
Merge pull request #4814 from zpao/build-react-dom-browser-2
Build react dom browser 2
2 parents c0270a1 + 3e67201 commit 69ab714

File tree

10 files changed

+96
-20
lines changed

10 files changed

+96
-20
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ packages/react-codemod/test/
1616
packages/react-codemod/scripts/
1717
packages/react-codemod/build/
1818
packages/react-codemod/node_modules/
19+
vendor/react-dom.js

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ script:
5252
-F "transformer=@build/JSXTransformer.js" \
5353
-F "react-with-addons=@build/react-with-addons.js" \
5454
-F "react-with-addons.min=@build/react-with-addons.min.js" \
55+
-F "react-dom=@build/react-dom.js"
56+
-F "react-dom.min=@build/react-dom.min.js"
5557
-F "npm-react=@build/packages/react.tgz" \
5658
-F "npm-react-dom=@build/packages/react-dom.tgz" \
5759
-F "commit=$TRAVIS_COMMIT" \

Gruntfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ module.exports = function(grunt) {
107107
'build-modules',
108108
'npm-react:release',
109109
]);
110+
grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom'));
110111

111112
grunt.registerTask('test', ['jest']);
112113
grunt.registerTask('npm:test', ['build', 'npm:pack']);
@@ -124,6 +125,7 @@ module.exports = function(grunt) {
124125
'browserify:addons',
125126
'browserify:min',
126127
'browserify:addonsMin',
128+
'build:react-dom',
127129
'npm-react:release',
128130
'npm-react:pack',
129131
'npm-react-dom:pack',

grunt/config/browserify.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,10 @@ var envifyDev = envify({NODE_ENV: process.env.NODE_ENV || 'development'});
1313
var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'});
1414

1515
var SIMPLE_TEMPLATE =
16-
'/**\n\
17-
* @PACKAGE@ v@VERSION@\n\
18-
*/';
16+
grunt.file.read('./grunt/data/header-template-short.txt');
1917

2018
var LICENSE_TEMPLATE =
21-
'/**\n\
22-
* @PACKAGE@ v@VERSION@\n\
23-
*\n\
24-
* Copyright 2013-2015, Facebook, Inc.\n\
25-
* All rights reserved.\n\
26-
*\n\
27-
* This source code is licensed under the BSD-style license found in the\n\
28-
* LICENSE file in the root directory of this source tree. An additional grant\n\
29-
* of patent rights can be found in the PATENTS file in the same directory.\n\
30-
*\n\
31-
*/';
19+
grunt.file.read('./grunt/data/header-template-extended.txt');
3220

3321
function minify(src) {
3422
return UglifyJS.minify(src, {fromString: true}).code;
@@ -38,17 +26,25 @@ function minify(src) {
3826
function bannerify(src) {
3927
var version = grunt.config.data.pkg.version;
4028
var packageName = this.data.packageName || this.data.standalone;
41-
return LICENSE_TEMPLATE.replace('@PACKAGE@', packageName)
42-
.replace('@VERSION@', version) +
43-
'\n' + src;
29+
return (
30+
grunt.template.process(
31+
LICENSE_TEMPLATE,
32+
{data: {package: packageName, version: version}}
33+
) +
34+
src
35+
);
4436
}
4537

4638
function simpleBannerify(src) {
4739
var version = grunt.config.data.pkg.version;
4840
var packageName = this.data.packageName || this.data.standalone;
49-
return SIMPLE_TEMPLATE.replace('@PACKAGE@', packageName)
50-
.replace('@VERSION@', version) +
51-
'\n' + src;
41+
return (
42+
grunt.template.process(
43+
SIMPLE_TEMPLATE,
44+
{data: {package: packageName, version: version}}
45+
) +
46+
src
47+
);
5248
}
5349

5450
// Our basic config which we'll add to to make our other builds
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* <%= package %> v<%= version %>
3+
*
4+
* Copyright 2013-2015, Facebook, Inc.
5+
* All rights reserved.
6+
*
7+
* This source code is licensed under the BSD-style license found in the
8+
* LICENSE file in the root directory of this source tree. An additional grant
9+
* of patent rights can be found in the PATENTS file in the same directory.
10+
*
11+
*/

grunt/data/header-template-short.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/**
2+
* <%= package %> v<%= version %>
3+
*/

grunt/tasks/react-dom.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
var grunt = require('grunt');
4+
var UglifyJS = require('uglify-js');
5+
6+
var LICENSE_TEMPLATE =
7+
grunt.file.read('./grunt/data/header-template-extended.txt');
8+
9+
module.exports = function() {
10+
var templateData = {
11+
package: 'ReactDOM',
12+
version: grunt.config.data.pkg.version,
13+
};
14+
var header = grunt.template.process(
15+
LICENSE_TEMPLATE,
16+
{data: templateData}
17+
);
18+
var src = grunt.file.read('vendor/react-dom.js');
19+
grunt.file.write(
20+
'build/react-dom.js',
21+
header + src
22+
);
23+
grunt.file.write(
24+
'build/react-dom.min.js',
25+
header + UglifyJS.minify(src, {fromString: true}).code
26+
);
27+
};

grunt/tasks/release.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var BOWER_GLOB = [BOWER_PATH + '*.{js}'];
77
var BOWER_FILES = [
88
'react.js', 'react.min.js', 'JSXTransformer.js',
99
'react-with-addons.js', 'react-with-addons.min.js',
10+
'react-dom.js', 'react-dom.min.js',
1011
];
1112
var GH_PAGES_PATH = '../react-gh-pages/';
1213
var GH_PAGES_GLOB = [GH_PAGES_PATH + '*'];

src/React.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ assign(React, {
6464
),
6565
});
6666

67+
React.__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactDOM;
68+
6769
module.exports = React;

vendor/react-dom.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Based off https://github.com/ForbesLindesay/umd/blob/master/template.js
2+
;(function(f) {
3+
// CommonJS
4+
if (typeof exports === "object" && typeof module !== "undefined") {
5+
module.exports = f(require('react'));
6+
7+
// RequireJS
8+
} else if (typeof define === "function" && define.amd) {
9+
define(['react'], f);
10+
11+
// <script>
12+
} else {
13+
var g
14+
if (typeof window !== "undefined") {
15+
g = window;
16+
} else if (typeof global !== "undefined") {
17+
g = global;
18+
} else if (typeof self !== "undefined") {
19+
g = self;
20+
} else {
21+
// works providing we're not in "use strict";
22+
// needed for Java 8 Nashorn
23+
// see https://github.com/facebook/react/issues/3037
24+
g = this;
25+
}
26+
g.ReactDOM = f(g.React);
27+
}
28+
29+
})(function(React) {
30+
return React.__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
31+
});

0 commit comments

Comments
 (0)