Closed robinplace closed 8 years ago
Ugh, hold off on this one... it's trickier than I thought with the way this package wraps react-redux
...
Indeed! We might be able to create a second dist file for jsnext main. It's a pretty optimized build already though, spent a whole day tweaking it last week :)
The problem I'm having is that rollup-plugin-commonjs doesn't understand the way the export is being done, so won't work:
import { connect } from `preact-redux`
So I'm having to put preact-redux in as a specifically named export in my rollup.config.js:
commonjs ({
include: 'node_modules/**',
namedExports: {
'preact-redux': [ 'connect', 'Provider' ],
},
}),
This is documented here in rollup-plugin-commonjs's README.
I just took a look at the source of rollup-plugin-commonjs and how it determines what can be imported from a CommonJS module and it looks like on line 165-ish its searching the file for this expression:
module.exports = { ... }
If I manually modify your dist/preact-redux.js
to do it's exporting in that style, rollup works perfectly. It's kind of funny situation because rollup-plugin-commonjs's code analysis is just looking for the string "module.exports"
and it doesn't care how or where if finds it.
So, is there an easy way to hack the build a tiny bit to make Rollup happy?
Or maybe we're better off dropping CommonJS entirely for rollup and creating a whole new build process to create an ES2015-style build? Maybe that way all the tree-shaking and magic can do it's stuff?
@robbiewxyz I have a solution, will post back in an hour or so! I should have used default
exports in the rollup build :)
@robbiewxyz The reason I've set up transpiling here is actually to prune a bunch of unnecessary stuff (proptypes, invariants, etc) out of react-redux
. It's about 10kb normally, but preact-redux
is 2kb.
I've copied the fix from another repo and released it as 1.2.0. Let me know if that worked! (sorry for the auto-close there)
This will let other packages do:
See https://github.com/rollup/rollup/wiki/jsnext:main, and
https://github.com/developit/preact/blob/master/package.json#L7.