Description
- I have searched the issues of this repository and believe that this is not a duplicate. I believe the only relevant thing is this comment Cannot bundle MuiThemeProvider.js with rollup #8100 (comment):
we would love to know if you can bundle the v1-beta branch with rollup.
Expected Behavior
Bundling with Rollup should work as long as MUI provides ES modules (https://github.com/rollup/rollup/wiki/ES6-modules#es6-friendly-libraries).
Current Behavior
Currently, there is an index.es.js
file which is an ES module itself, but it points at CommonJS modules (https://unpkg.com/[email protected]/index.es.js). This then causes Rollup to fail to build:
[!] Error: 'BottomNavigationAction' is not exported by node_modules/material-ui/BottomNavigation/index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
node_modules/material-ui/index.es.js (9:38)
7: export { default as Avatar } from './Avatar';
8: export { default as Badge } from './Badge';
9: export { default as BottomNavigation, BottomNavigationAction } from './BottomNavigation';
^
10: export { default as Button } from './Button';
11: export { default as ButtonBase } from './ButtonBase';
Presumably, this is because https://github.com/rollup/rollup-plugin-commonjs cannot fully understand the CommonJS exports (unless you manually specify them via namedExports
option).
Steps to Reproduce (for bugs)
I have a simple repro available here: https://github.com/NMinhNguyen/material-ui-rollup-example
It also contains a branch where I modified yarn.lock
to point at a temporary fork of MUI that publishes ES modules (source), and bundling with Rollup works without any other changes. I am willing to raise a PR with this change (I'll probably also replace the current build:es2015modules
script as I believe my change supersedes it, but not sure if removing index.es.js
could be considered a breaking change?), but I thought I'd raise an issue first (this is also what the contributing guide suggests) 🙂
I have also created this branch where I committed the current build output and how it changes with my changes so you can more easily review them as well as spot any possible regressions. And here you can find the actual ES5 modules.
By the way, the reason I would rather not use the es
folder is because that folder is ESNext (2015+), so I'd have to transpile it via Babel myself. This would mean that I'd additionally have to include these plugins to ensure I get the same Babel transformations applied: https://github.com/mui-org/material-ui/blob/8497cd976d74cfd102c6e8afb932348b366dd5b3/.babelrc#L70-L83
Context
We are using Rollup to bundle our code.
Your Environment
Tech | Version |
---|---|
Material-UI | 1.0.0-beta.32 |
React | 16.2.0 |
Rollup | 0.55.3 |
rollup-plugin-commonjs | 8.3.0 |