Skip to content

Commit 9647f75

Browse files
committed
use node polyfill plugin & fast-text-encoder
see shakacode/react_on_rails#1457 (comment)
1 parent 7aef57d commit 9647f75

File tree

9 files changed

+1027
-49
lines changed

9 files changed

+1027
-49
lines changed

lib/assets/react-source/development/react-server.js

Lines changed: 296 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/assets/react-source/development/react.js

Lines changed: 2 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/assets/react-source/production/react-server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/assets/react-source/production/react.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react-builds/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"main": "react.js",
66
"dependencies": {
77
"create-react-class": "^15.6.2",
8-
"fastestsmallesttextencoderdecoder": "^1.0.22",
8+
"fast-text-encoding": "^1.0.6",
99
"immutability-helper": "^2.4.0",
10+
"node-polyfill-webpack-plugin": "^2.0.1",
1011
"prop-types": "^15.6.0",
1112
"react": "^18.2.0",
1213
"react-dom": "^18.2.0",

react-builds/react-browser.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ var React = require("react");
22
var ReactDOM = require("react-dom");
33
var createReactClass = require("create-react-class");
44
var PropTypes = require("prop-types");
5-
var {TextEncoder, TextDecoder} = require("fastestsmallesttextencoderdecoder");
65

76
window.React = React;
87
window.ReactDOM = ReactDOM;
98
window.createReactClass = createReactClass;
109
window.PropTypes = PropTypes;
11-
window.TextEncoder = TextEncoder
12-
window.TextDecoder = TextDecoder

react-builds/react-server.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
// polyfill TextEncoder & TextDecoder onto `util` b/c `node-util` polyfill doesn't include them
2+
// https://github.com/browserify/node-util/issues/46
3+
import util from 'util';
4+
import 'fast-text-encoding';
5+
6+
Object.assign(util, { TextDecoder, TextEncoder });
7+
18
var React = require("react");
29
var ReactDOMServer = require("react-dom/server");
310
var createReactClass = require("create-react-class");
411
var PropTypes = require("prop-types");
5-
var {TextEncoder, TextDecoder} = require("fastestsmallesttextencoderdecoder");
612

713
global.React = React;
814
global.ReactDOMServer = ReactDOMServer;
915
global.createReactClass = createReactClass;
1016
global.PropTypes = PropTypes;
11-
global.TextEncoder = TextEncoder
12-
global.TextDecoder = TextDecoder

react-builds/webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Use `rake react:update` to build this bundle & copy files into the gem.
22
// Be sure to set NODE_ENV=production or NODE_ENV=development before running
3+
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
34

45
module.exports = {
56
context: __dirname,
@@ -11,4 +12,9 @@ module.exports = {
1112
path: __dirname + "/build/" + process.env.NODE_ENV,
1213
filename: "[name].js",
1314
},
15+
plugins: [
16+
new NodePolyfillPlugin({
17+
excludeAliases: ['console', 'Buffer'],
18+
}),
19+
],
1420
};

0 commit comments

Comments
 (0)