Skip to content
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

Release a umd build? #95

Closed
gutenye opened this issue Jun 3, 2016 · 9 comments
Closed

Release a umd build? #95

gutenye opened this issue Jun 3, 2016 · 9 comments
Milestone

Comments

@gutenye
Copy link
Contributor

gutenye commented Jun 3, 2016

This library is great, thank you for your work. Is it possible to release a umd build? For example, the react node module contains a umd build by itself.

@mlaursen
Copy link
Owner

mlaursen commented Jun 3, 2016

I can look into the umd build. I haven't actually worked with umd before, but it does look like there are a few tools out there for it so it might be relatively painless.

@mlaursen mlaursen added this to the v1.0.0 Release milestone Jun 3, 2016
This was referenced Jun 14, 2016
@mlaursen mlaursen modified the milestones: v0.3.1, v1.0.0 Release Jun 15, 2016
@mlaursen
Copy link
Owner

Versions 0.3.1 and up should now support UMD. I have published 0.3.1 today. Let me know if you run into any problems.

@gutenye
Copy link
Contributor Author

gutenye commented Jun 17, 2016

@mlaursen 👍

@gutenye
Copy link
Contributor Author

gutenye commented Jun 18, 2016

Can you provide an example: how to use it?

@mlaursen
Copy link
Owner

If i am understanding UMD correctly, it is just a way to allow AMD and RequireJS. Here are some examples for AMD, RequireJS, and es6 module imports. I am assuming you can use ES6 in your project though.

// AMD

require(['react', 'react-dom', 'react-md/lib/Cards'], function(React, ReactDOM, Cards) {
  const { Card, CardText } = Cards;

  ReactDOM.render(
    <Card>
      <CardText>This is some text for a card</Card>
    </Card>,
    document.getElementById('app')
  );
});
// RequireJS

const React = require('react');
const ReactDOM = require('react-dom');
const Cards = require('react-md/lib/Cards');

const { Card, CardText } = Cards;

ReactDOM.render(
  <Card>
    <CardText>This is some text for a card</Card>
  </Card>,
  document.getElementById('app')
);
// ES6 Modules

import React from 'react';
import ReactDOM from 'react-dom';
import { Card, CardText } from 'react-md/lib/Cards';

ReactDOM.render(
  <Card>
    <CardText>This is some text for a card</Card>
  </Card>,
  document.getElementById('app')
);

I am honestly guessing on the AMD implementation though. There aren't too many examples I can use to base that off of.I just know that my compiled sources in lib reflect this article: http://davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/#umd-universal-module-definition

@gutenye
Copy link
Contributor Author

gutenye commented Jun 18, 2016

Actually, I want to use it in browser, for testing and learning purpose without create a whole new project.

For example, use React in a single html file.

<!DOCTYPE html>
<html>
  <body>
  <div id="app"></div>
  <script src="node_modules/react/dist/react.js"></script>
  <script src="node_modules/react-dom/dist/react-dom.js"></script>
  <script src="node_modules/node_modules/babel-core/browser.js"></script>
  <script type="text/babel">
    class App extends React.Component {
      render() {
        return <div>hello</div>
      }
    }

    ReactDOM.render(<App />, document.querySelector("#app"))
  </script>
</html>

I think react use webpack to generate one single umd dist file.

@mlaursen
Copy link
Owner

Ahh ok. I didn't understand the ticket then. I'll reopen and set that up!

@mlaursen
Copy link
Owner

Ok, my latest pull request (and release 0.3.2+) will work in the browser or through the normal amd/requirejs/es modules imports.

I am not sure what version of babel you are using since 6+ removed the browser support.. but i got it working using the babel-standalone.

So here was the index.html I used.

<!DOCTYPE html>
<html>
  <head><link href="node_modules/react-md/dist/react-md.css" rel="stylesheet"></head>
  <body>
  <div id="app"></div>
  <script src="node_modules/react/dist/react-with-addons.js"></script>
  <script src="node_modules/react-dom/dist/react-dom.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.7.7/babel.min.js"></script>
  <script src="node_modules/react-md/dist/react-md.js"></script>
  <script type="text/javascript">
    const input = `
const { Card, CardText } = ReactMD;

class App extends React.Component {
  render() {
    return (
      <Card>
        <CardText>Hello, world!</CardText>
      </Card>
    );
  }
}

ReactDOM.render(<App />, document.querySelector("#app"));
`;

eval(Babel.transform(input, { presets: ['es2015', 'react', 'stage-0'] }).code);
  </script>
</html>

So every component is now accessible through the global ReactMD and you need to make sure to use the react-with-addons instead of react since this project relies on those peer dependencies.

@gutenye
Copy link
Contributor Author

gutenye commented Jun 19, 2016

It's working. Thank you very much.

I use babel 5, and they have discussed about supporting 'text/babel' type in babel-standalone

@gutenye gutenye closed this as completed Jun 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants