How to create material-ui.js file?

坚强是说给别人听的谎言 提交于 2019-12-01 08:15:45

问题


I've followed the getting started guide and have the example running, but it seems to load all of the js components from the example lib folder as separate resources. How do I get it to build a single material-ui.js (or material-ui.min.js) file which I just reference from my html? Do I use npm, gulp, browserify, etc? If so, how? I am not at all familiar with the javascript build and packaging tools. I just want a single js file to include in my static resources, like react.min.js


回答1:


npm install material-ui
npm install -g webpack
webpack node_modules/material-ui/lib/index.js material-ui.js

You're probably using babel to transform your inline jsx (ie. following the React tutorial), so you can use the es6 import syntax:

import React from 'react';
import FlatButton from 'material-ui/lib/flat-button';

The whole script block is:

<script type="text/babel">      
    import React from 'react';
    import FlatButton from 'material-ui/lib/flat-button';


    const FlatButtonExampleSimple = () => (
      <div>
        <FlatButton label="Default" />
        <FlatButton label="Primary" primary={true} />
        <FlatButton label="Secondary" secondary={true} />
        <FlatButton label="Disabled" disabled={true} />
      </div>
    );      

    ReactDOM.render(
      <FlatButtonExampleSimple />,
      document.getElementById('content')
    );
</script>



回答2:


you have to follow the guids

First go to example folder

cd <project folder>/material-ui/examples/browserify-gulp-example

Run this

npm install

It will install all required packages described in package.json

Then

npm start

It will run web server

And finally just run gulp

gulp

It will run all gulp tasks described here

browserify-gulp-example/gulp/tasks

In result you will come with file app.js in build folder

You can include it in your html as usually

<script src="app.js"></script>

Now you can run http://localhost:3000 and check for result



来源:https://stackoverflow.com/questions/32372449/how-to-create-material-ui-js-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!