-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Bundle umd with rollup #681
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import nodeResolve from 'rollup-plugin-node-resolve' | ||
import babel from 'rollup-plugin-babel' | ||
import replace from 'rollup-plugin-replace' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import uglify from 'rollup-plugin-uglify' | ||
|
||
const env = process.env.NODE_ENV | ||
|
||
const config = { | ||
entry: 'src/index.js', | ||
external: [ | ||
'react', | ||
'redux' | ||
], | ||
globals: { | ||
'react': 'React', | ||
'redux': 'Redux' | ||
}, | ||
format: 'umd', | ||
moduleName: 'ReactRedux', | ||
plugins: [ | ||
nodeResolve(), | ||
babel({ | ||
exclude: '**/node_modules/**' | ||
}), | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify(env) | ||
}), | ||
commonjs() | ||
] | ||
} | ||
|
||
if (env === 'production') { | ||
config.plugins.push( | ||
uglify({ | ||
compress: { | ||
pure_getters: true, | ||
unsafe: true, | ||
unsafe_comps: true, | ||
screw_ie8: true, | ||
warnings: false | ||
} | ||
}) | ||
) | ||
} | ||
|
||
export default config |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, do we have to externalize Babel's helpers? This introduces a rather opaque dependency, since it's not explicitly listed in package.json or anything. What if we use transform-runtime instead to centralize helpers within the build? Does that bloat things a lot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then tree shaking removes unnecessary helpers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, confused by github reviews.
rollup-plugin-babel calls buildExternalHelpers, adds it as virtual module and then tree shake unnecessary code. So all in the same bundle, not external package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, transform-runtime should only add used helpers by itself. But there can be a tree of helpers using other helpers underneath that. I would just ensure the
{ polyfills: false }
option is used so it doesn't try to polyfill everything. That can be left up to the user.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't try to polyfill everything. Used is only what added by plugins in .babelrc. And it looks like runtime plugin adds
core-js
stuff under the hood. And it's common js afaik.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but I don't know how to best advertise to UMD users that they need this thing that isn't in the dependency list. It seems really error-prone.
I'll do some checking into this when I have a chance later tonight. I'm sure this stuff can be inlined without causing a ton of bloat. It's a babel issue, not webpack or rollup's job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want one more dependency for umd users? Now helpers are builtin with umd bundle. You want to make life harder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'm saying don't make them external. If you do, that becomes a dependency.
transform-runtime
inlines and centralizes helpers, so they don't need to be imported by the user, but are still efficient because there is only ever one copy of a helper.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and that what rollup-plugin-babel do. External plugin just add namespace to helpers which is used by rollup-plugin-babel. But that happen without additional and not always efficient work by commonjs plugin and expliit dependency which developer should specify instead of what exactly plugins require.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I apparently have a fundamental misunderstanding of babel-plugin-external-helpers or rollup-plugin-babel does :P
external-helpers is supposed to tell the transpiled code to look at
global
for thebabelHelpers
property to find them. That means they should be external (like the name implies) from the build and included via a separate<script>
tag. For whatever reason, rollup-plugin-babel actually treats them like an inline-able dependency, which is what transform-runtime is supposed to do.Anyways, that's just my 2 cents. Since the naming is backwards, this is actually what we want and I was wrong about it originally :)