-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
[WIP] [Core] Setup umd build #4342
Conversation
@ANich Nice work. One thing I think is important, however we arrive at it, is allow the component imports currently defined in the examples to work as-is. This way we will be able to push them unmodified to codepen or similar via the API, without having to rewrite the imports (although we'll still need to take care of putting the theme on context). @EloB did something similar to that here: #3997 (comment) (explanation is a couple of comments down). Edit: I realised after I wrote that that it didn't make sense. 😄 And in this case, it looks like they're imported from the main |
Hey @mbrookes thanks! Hmm, did you mean some way to get all of the components available under the window instead of a MaterialUI object? See 1f4165c , Related: is exporting all of these from Edit: 'They' meaning everything, everything from |
Is that even possible? :) However, if we're going to have to do some kind of inline code-mode on the docs site examples when they are pushed to the codepen API in order to get them working with a standalone build, it may not matter so much what the imports look like. @EloB's approach at least means that the import resembles something that would work (albeit inefficiently without tree shaking) if you were to copy them from codepen into a local project:
|
Here's @EloB's version working with the To make the examples work, all we'd need to do is:
Should be possible to do that on the fly, but worst case we can have a build script that converts the examples as part of the docs site build. (Same in CodePen: http://codepen.io/mbrookes/pen/gMYZzV) |
No idea 😅 I'm not exactly sure what you mean by:
By as-is do you mean verbatim?
Sure thing: https://jsfiddle.net/jfr174ck/2/ I took the first example from the usage page and ran it through the babel repl. This was my interpretation of what someone might write if they were using the umd build without babel or any other node technology in their workflow. That being said, React, ReactDOM must also be included separately and babel would have to be included separately from a CDN or js file to access imports or jsx. Here's my rawgit URL (Rawgit is pretty cool thanks for the new tool!) |
@mbrookes With @ANich's latest push, we should have all of the components and style related files exported under index (in his new Also, in the umd build, What do you think of this approach?
I agree, sounds like a good build related activity. If the approach for making the browser build looks good, maybe we could merge this first. That way we can get it up in a CDN for our next release and start sorting out codebin integration. |
@ANich Looks like there is some interesting behavior when we click the Button in your jsfiddle, getting some errors in the console. Not sure if it's code or build related yet...mmmm |
@newoga Yeah you're right. Also for some reason, I couldn't reproduce the errors on Firefox. For reference, these are the errors on Chrome:
Maybe worth opening an issue about? |
Are you suggesting this might be used outside of code play-pens? Material-UI isn't intended to be used as a monolithic lib, so to me the primary use-case is pretty clear, and we should be developing towards that, rather than a hypothetical user who don't want to use build tools. If their own code is so simple that it doesn't need to be modular, then dragging a 1.5MB library along for the ride would be crazy. 😜
TBH I much prefer the resulting code in codepen using the alternate approach. It bears a much closer resemblance to the original examples, having ES6 imports, and will make it easier to go both directions, for example taking a modified example from codepen that reproduces a bug in a Material-UI component, and dropping it back into the docs site for further testing and development. Edit: Add attribution. |
@mbrookes This PR isn't about modifying examples, just creating the browser build of Material-UI (which is a stepping stone to using it for examples on sites like codebin and jsfiddle). How this is currently setup is pretty much how every other React project creates their browser build. It's up to the user to include additional dependencies like React, and babel if they want to use ES6. Maybe I'm not understanding what alternative approach your are suggesting. Could you re-explain? 😄 |
To use with the examples. In codepen. So how the build is generated, and what the resulting imports look like when used in a code play-pen is absolutely relevant.
The one that results in a browser build that can be used like this: |
@mbrookes Your requirements (and codepen compatibility) is satisfied by this PR minus a few differences, which is why I'm confused what you're asking for?
That's done. All components and files underneath styles are now accessible under
That's fine, provided the user loads react and react-dom themselves. Call to
That's also not a problem. |
The only problem I think we have is related to an error we're getting in some browsers (which I think is related to material-ui's use of |
No, it's me that's confused. 😜 Webpack is a black art (that I haven't studied), so I can only base my assessment on the end result, rather than the webpack config, which is why I asked for a working jsfiddle. I should probably have linked to my codepen or jsfiddle rather than the comment, but the main difference between the two that I'm concerned about is having to use this:
(or this:
)
|
@ANich Can you fix that |
We also need to decide what the target directory should be - |
I agree. 👍 I've seen |
@newoga Sounds good. Also, what about the object name? |
I don't have a strong opinion about that one. I find most projects just pick the pascal case of their package name. But I wouldn't argue if the consensus was leaning towards something else. |
If that's the norm, I'm fine with that. |
@mbrookes I've left it as MaterialUI per Pascal Case
I've changed the directory to dist and added it to the See 342f497
@newoga I'm not 100% sure where to go with this, I've tried using This might be useful, changing the order of the external scripts ( |
@ANich Interesting. I just noticed we also have In
|
@nathanmarks @newoga @mbrookes Updated the code 👍 https://jsfiddle.net/jfr174ck/12/ I did a rebase and pushed to my branch, do I need to anything else to get this merged? |
What is missing in this to be merged? :) |
The versions generated with this are going the version that will eventually go to CDNS? |
53b828e
to
ea2538e
Compare
Ping @nathanmarks @newoga @mbrookes |
Just tested this and seems like there is a problem:
MuiThemeProvider is exported both from Perhaps stuff from |
Can be used to generate rollup.js it |
I tried this but I am getting errors when I load the module. Also npm install && npm run build:umd is broken as of 4 days ago since the react-tap-event-plugin updated to 2.0.1. Same problem as @Deraen, how did you resolve it btw? I appended 2 to the MuiThemeProvider import in ./src/index.js. If I load it as text/javascript it gives error, "Uncaught TypeError: Cannot redefine property: MuiThemeProvider" On line 79 of MaterialUI.js "Object.defineProperty(exports, key, {" Also is it just me or are SvgIcons and FontIcons not working with this UMD build? |
"build:icon-index": "babel-node ./scripts/icon-index-generator.js", | ||
"build:babel": "babel ./src --ignore *.spec.js --out-dir ./build", | ||
"build:copy-files": "babel-node ./scripts/copy-files.js", | ||
"build:umd": "cross-env NODE_ENV=development webpack src/index.umd.js dist/MaterialUI.js", | ||
"build:min": "cross-env NODE_ENV=production webpack -p src/index.umd.js dist/MaterialUI.min.js", |
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.
These two targets gave errors for me. I changed them to:
"build:umd": "cross-env NODE_ENV=development webpack src/index.umd.js --output-filename dist/MaterialUI.js",
"build:min": "cross-env NODE_ENV=production webpack -p src/index.umd.js --output-filename dist/MaterialUI.min.js",
and the build ran correctly.
@nealeu Do icons and touch events work for you? Im thinking if I should just try and apply this umd build patch to the next branch, which removes reacttouchevents and uses onClick. |
@vans163 So far, yes. The only issue I've found so far is with un-docked Drawer. swipe to open and close work okay, but click on overlay to dismiss doesn't work. I'm adding an explicit close icon at the top of in the menu to deal with that. |
@nealeu Good to know it can actually work. I will try to apply this to the 'next' branch and see if the switch to using onClick fixes the undocked Drawer issue. EDIT: Still struggled with this, onTouchEvent was still broken. Using next branch nothing at all would render. Ended up using this UMD build https://github.com/cljsjs/packages/tree/master/material-ui. It correctly applies the troublesome react-tap-event-plugin, and it correctly considers the SVG images plus other misc stuff that ANich missed. |
Hi, My feeling on this is that Material UI should work fully with onClick so that it's desktop compatible. I think a separate pull request is needed which is to use onClick in the places it is needed. I'll start one. |
@nealeu The 'next' branch I think is the one that uses onClick in most places, even though its called onTouchTap (for backwards compatibily as I understand it), it has no dependency on react-tap-event-plugin. But the next branch is totally undocumented and when I switch to it with my working code, it just rendered a blank page. |
@vans163 Ah thanks. I hadn't spotted that. I'll rebase off it and see how I go. |
@nealeu Be careful its missing components compared to master (such as stepper), I think the pull req you opened is more accurate. next seems to be still in heavy development. |
I'm closing this PR as #262 has been resolved. Thanks for your help guys. |
Resolves #262
Hi first time contributor here,
npm run build:umd
script creates a standaloneMaterialUI.js
in the build/umd dir. Likewisenpm run build:min
creates a minified versionMaterialUI.min.js
.I tried including it in a script tag and the components were available under the
MaterialUI
object, but I haven't tested it completely. Is this sufficient?I included
react-tap-event-plugin
as an external, though I'm not sure if it has an external build. Should it remain?