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

Generate UMD build with Rollup #964

Closed
wants to merge 3 commits into from
Closed

Conversation

Rich-Harris
Copy link

This PR generates a UMD build with Rollup, per @gaearon's suggestion on #928. The goal is to produce more compact, readable output.

It doesn't change the build:lib task, as Rollup only bundles modules rather than doing 1:1 transpilation, but I could amend the PR to create a CommonJS bundle in lib if that's desirable.

Zipped size is 14.5% smaller than the current build:

Unminified Minified Gzipped
Current 21643 5402 1904
With Rollup 16177 3978 1628

@timdorr
Copy link
Member

timdorr commented Nov 18, 2015

@gaearon What do you think about this? One of the nice side benefits is a more readable UMD output, and a removal of the ugly Webpack bootstrap code. The tradeoff being you now have two build tools in the same project. But for the UMD end user, it's a win.

@gaearon
Copy link
Contributor

gaearon commented Nov 18, 2015

@timdorr

I want to wait for Lodash 4 to come out and then revisit, per #928 (comment)

var replace = require( 'rollup-plugin-replace' );

var env = process.argv[2] === '--prod' ? 'production' : 'development';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about process.argv.indexOf('--prod') >= 0, then it can be on any argument.

@thisconnect
Copy link

I'd love to use redux in a project where we rollup everything. As far as I know, it is not possible to rollup an application that imports redux, neither with redux's main, jsnext:main nor the dist/redux.js. :(
umd or es6 would let us use redux. hope this gets merged.

@gaearon
Copy link
Contributor

gaearon commented Jan 30, 2016

Redux has UMD build in dist folder.

@gaearon
Copy link
Contributor

gaearon commented Feb 1, 2016

I'd love to use redux in a project where we rollup everything. As far as I know, it is not possible to rollup an application that imports redux, neither with redux's main, jsnext:main nor the dist/redux.js. :(

Can you please explain why Redux currently cannot be used with Rollup?

@thisconnect
Copy link

@gaearon Hi, sorry for my delay. I finally succeeded building a simple redux example (yes!!!) using some of @Rich-Harris PR's ideas. The main issue that it did not work in the first place was that I was missing replace({ 'process.env.NODE_ENV': JSON.stringify('production') }).
It did build but error'd in the browser Uncaught ReferenceError: process is not defined. With "replace process" stuff all works fine!

I setup a gist with 2 builds, one using es6 import and one commonjs require. Download npm i && npm start then open the html in a browser. Note: the minified version of es6 import has about half the size of the one built from commonjs with requires and no jsnext.

https://gist.github.com/thisconnect/af9c83ed56e9d554f63b

Thanks btw for the video's I love them! :)

@simplesmiler
Copy link

@gaearon jsnext:main of redux points to the es6 code, which breaks rolling up (this can be worked around with plugins). I believe the consensus is to point jsnext:main to the transpiled code with only imports/exports left intact.
Reference: rollup/rollup#337 (comment)


EDIT: #1042

@gaearon
Copy link
Contributor

gaearon commented Feb 5, 2016

@simplesmiler

I'm happy to fix it but I can't figure out how to create a Rollup project reproducing the issue with Redux. Can you help me by pointing me at one?

@TrySound
Copy link
Contributor

TrySound commented Feb 5, 2016

@gaearon via cli rollup --config rollup.config.js

import npm from 'rollup-plugin-npm';

export default {
  entry: 'src/index.js',
  dest: 'dist/index.js',
  format: 'iife',
  plugins: [
    npm({ jsnext: true })
  ]
};

@Rich-Harris
Copy link
Author

The best way I've found to use Redux with Rollup is by building it separately: https://github.com/Rich-Harris/rollup-redux-debug. Lil' bit hacky but it works, and is very space-efficient! #1042 would render the custom build unnecessary.

@gaearon gaearon mentioned this pull request Feb 5, 2016
@thisconnect
Copy link

Thanks, looks great! Updated gist to use Redux 3.3.1 and removed commonjs plugin.

main.iife.min.js shrank from 2,972 bytes (with Redux 3.2.1) to 2,202 bytes (with Redux 3.3.1)

@gaearon
Copy link
Contributor

gaearon commented Mar 6, 2016

I’m still up for adding this, but it currently doesn’t merge cleanly.
Lodash 4 is out so seems like the only thing blocking this is now fixed.
If you’d like, please rebase and I’ll gladly reopen and merge.

@gaearon gaearon closed this Mar 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants