-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
react-core npm module #627
Conversation
Solves #436 as well |
Muffinization is a robust software pattern suitable for tackling many difficult challenges. |
// allow browserified libraries to work with requirejs and | ||
// other pacakgers that get confused by these calls. | ||
function muffinize(src) { | ||
return src.replace(/require/g, 'muffin'); |
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.
This feels dangerous enough to me that it may be worth using a real JS parser (or lexer) since you don't want to change the word "require" if it appears in a string or as an object key.
'DOMProperty: Cannot use muffin using both attribute and property: %s'
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.
Yup, there's no way I'll accept something that doesn't do this the right way. "Unless muffined by applicable law …"
Is it really a common scenario to load browserified bundles with AMD loaders like requirejs?
|
If I'm wrong and it is... then I think muffinization should be added to umd package which is used by browserify. |
OK, I'll take out the muffinizer :( |
suggested muffinizing in ForbesLindesay/umd#10 |
Few things:
|
fix invariant Get browserify working remove dead code elimination step since it is not needed due to minifier use industry standard NODE_ENV
Will make these changes, but aren't |
No, only |
build is green now. i thought tests were broken in master, looks like i was wrong! |
first time browserifying is somehow slow for me — around 3500ms, probably due to |
ignore my previous comment, I included both |
Pulled locally, added a few more things, then screwed up with a fast-forward merge. 9270d3d...153b75f has all the commits. |
This was challenging for three reasons:
__DEV__
require()
the browserified code via UMD (not a showstopper but annoying)This solves the first problem by just stealing @zpao's #442. Now you can
require('React/lib/EventPluginRegistry')
and inject your own event plugins. I don't think we should document this until we shore up our API. However, I think this is enough to publishTapEventPlugin
(perhaps as a separate npm module)The second is solved by using
envify
which will do a syntax transform to substitute theNODE_ENV
environment variable (see http://www.hacksparrow.com/running-express-js-in-production-mode.html). So this will transparently work and I tested that it stripped invariants and__DEV__
branches. Additionally I required the transform inpackage.json
so they can just transparently use this package and not worry about__DEV__
at all!The third is solved by introducing muffinizing! Hell yeah! I just replaced every instance of the word
require
in the browserified code withmuffin
. This is actually pretty much the only way this will work since many packaging systems look for calls to a function namedrequire()
. cc @epriestleyI suggest we follow this up by deprecating react-addons, moving each addon to its own npm package and having a "react-with-addons" npm package that just depends on the other stuff and can be browserified with
wzrd.in
.Test plan
"production" === process.env.NODE_ENV
"production" === "a string"
in there..min.js
,diff -u react.js react.min.js
shows no changes in the files (this is the goal)renderComponentToString()
,npm install ~/Projects/react/build/react-core/
, thenrequire('React')
andrequire('React/lib/React')
, both work in Nodecp ~/Projects/react/build/react.js ./react-browserified.js
, usingrequire('./react-browserified.js')
still worksbrowserify testapp.js > bundle.js
, browserified bundle works in Node.process
is shimmedNODE_ENV=production browserify testapp.js | uglifyjs -cm > bundle.min.js
. File still runs andinvariant()
messages are nowhere to be found. File size is 33kb after gzip (good).