Material-ui: Support Webpack 2 / Rollup Tree shaking

Created on 10 Nov 2016  路  5Comments  路  Source: mui-org/material-ui

Basically it's enough to

  1. Copy src/index.js to build/index.es.js
  2. Add module and jsnext:main entries to package.json that will target this file

So webpack 2 / rollup users can import components as we did it at beginning

import {Dialog, FlatButton, TextField, SelectField} from 'material-ui'`

And don't worry about bundle size

cc: @nathanmarks , @oliviertassinari i can create pr later today, if you're interested

Most helpful comment

Hi, I've been trying to setup material-ui@next with tree shaking but can't seem to make it work. I've tried both create-react-app and setting up a project with webpack (v4). In short,

import Button from 'material-ui/Button' // this works

but

import { Button } from 'material-ui' // this does not

Is there a sample project or somewhere I can see how to set this up with tree shaking since I think I'm doing something wrong.

All 5 comments

@umidbekkarimov That would definitely be a great addition! I have never played with it. I would love to see a PR 馃憤 .

Hey guys has anyone gotten this to work? I'm having the same issue as Dan here, in a create-react-app. create-react-app uses Webpack 2, so I'm assuming this should be working out of the box. You can respond here, but I'm sure Dan would appreciate a response as well!

https://github.com/facebookincubator/create-react-app/issues/2748

Hi, I've been trying to setup material-ui@next with tree shaking but can't seem to make it work. I've tried both create-react-app and setting up a project with webpack (v4). In short,

import Button from 'material-ui/Button' // this works

but

import { Button } from 'material-ui' // this does not

Is there a sample project or somewhere I can see how to set this up with tree shaking since I think I'm doing something wrong.

@divyanshu013 I got the same problem

Side note, Parcel has been working on an experimental support for tree shaking. It seems to work out of the box with Material-UI. To be confirmed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

TimoRuetten picture TimoRuetten  路  3Comments

sys13 picture sys13  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments

rbozan picture rbozan  路  3Comments