I recently read on Material-UI's docs:
Notice that in the above example, we used:
import RaisedButton from 'material-ui/RaisedButton'
instead of
import {RaisedButton} from 'material-ui'
This will make your build process faster and your build output smaller.
I used to thought that it was exactly the same, but actually, this means that the second lines is juste like:
import materialUI from 'material-ui'
const {RaisedButton} = materialUI
And it will produce the exact same bundle, right?
I did some tests, comparing bundles size use different combinaisons of importing with 2 files:
index.js:
import RaisedButton from 'material-ui/RaisedButton'
// or import {RaisedButton} from 'material-ui'
import file from './otherFile.js'
console.log(RaisedButton)
console.log(file)
otherFile.js
import RaisedButton from 'material-ui/RaisedButton'
// or import {RaisedButton} from 'material-ui'
export default RaisedButton
The results are quite as expected using only import RaisedButton from 'material-ui/RaisedButton'
the bundle will be something like 24k LoC (material-ui loads React dependencies). Using import {RaisedButton} from 'material-ui'
, in one or both file(s), the bundle will be something like 57k LoC.
My question is mainly about performances and best practices, with a small usage of Material-UI I should always import from 'material-ui/ComponentName
, but if I use a lot of Material-UI components on a bigger project, it won't impact the bundle size if I use import {Comp1, Comp2, Comp3} from 'material-ui'
as the whole package will be imported only one time in the bundle?