-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Custom bundle script details #5527
Conversation
I wonder if a better default wouldn't be minified+sourcemaps, and then a single flag to do unminified+no_sourcemaps... Or maybe we always output all three? |
- include all traces, transforms and calendars by default - minify by default
In ca4d557 the default is changed to minified. |
sourcemaps should not increase the bundle size... sourcemaps should appear in a separate file next to the bundle, right? |
Right now it is included in the bundle. |
Maybe we should try this: browserify/browserify#339 |
Let's definitely not do that :) Ideally sourcemaps are just another file on the side, that is only loaded by dev tools, and otherwise ignored by regular users. |
It appears achieving that with |
Hmmm that's quite disappointing. Are you sure? this is a very standard way of using sourcemaps... If they must be inlined and therefore bloat the minified bundle, there'd be no point in minifying :) |
I don't know if this is what you mean by "complicate our build process even more" - at least on the command line it seems straightforward https://github.com/browserify/browserify-handbook#exorcist |
tasks/partial_bundle.js
Outdated
var out = args.out ? args.out : 'custom'; | ||
var traces = inputArray(args.traces, allTraces); | ||
var transforms = inputArray(args.transforms, allTransforms); | ||
var calendars = inputBoolean(args.calendars, true); |
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.
presumably at some point we will make more of the components registered in core optional. In order to support this in a backward-compatible way, perhaps we can make an option like skipcomponents=calendars
, to later expand to allow skipping other components?
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.
I also thought about this a bit. But I think another option that we want to provide in future is which calendar(s) to add. That can explain why calendars
logic here is quite similar to transforms
and traces
. For the moment it is handled by a boolean; but it could be expanded to a list.
Perhaps to avoid confusion we can move calendars
code from ./components/calendars
to ./calendars
now or once we split it?
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.
As discussed on slack, for now let's drop the calendars option - always include calendars in every bundle - until we can ensure that unrelated functionality like connectgaps
will not break as in #4883.
At ~81kB minified and rarely used, it would be very nice to make these optional eventually, and you're right to want flexibility even when world calendars are requested to only include the necessary ones, not all of them
If we can get the source map in a separate file, then yes minified with source map should be the default. At that point I don't see a reason you'd want to invert either of those options (for dash and dash components that's all we provide), but I also don't see much harm keeping them. |
Nice find. I was looking at other npm modules actually. BTW |
Co-authored-by: Alex Johnson <[email protected]>
tasks/util/browserify_wrapper.js
Outdated
if(sourceMap) { | ||
bundleStream | ||
.pipe(applyDerequire()) | ||
.pipe(exorcist(sourceMap)) |
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.
This is generating the sourcemap of the unminified bundle. The real value is in a sourcemap of the minified bundle (which, for clarity, gets extension .min.js.map
), then you never need the unminified bundle.
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.
Good call. Addressed in 7d0145a.
FYI - thlorenz/exorcist#47 |
if(unminified) { | ||
opts.dist = path.join(constants.pathToDist, 'plotly-' + out + '.js'); | ||
} else { | ||
opts.distMin = path.join(constants.pathToDist, 'plotly-' + out + '.min.js'); |
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.
To avoid name conflicts (let's say one uses e.g. basic
in output name with different traces), wondering instead of plotly-*
shouldn't we use plotly_*
here?
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.
On the other hand folks making custom bundles will likely be used to our partial bundles already, so may be tripped up by the switch from -
to _
. Let's keep -
, these bundles won't be published anyway.
tasks/partial_bundle.js
Outdated
new RegExp( | ||
WHITESPACE_BEFORE + | ||
'require\\(\'\\./' + t + '\'\\)' + | ||
(t === 'calendars' ? '' : ','), // there is no comma after calendars 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.
Feels a bit fragile - can we either just make the comma optional in the pattern, or add the comma in lib/index
so all the lines are equivalent?
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.
💃 LGTM! Just one nonblocking comment remaining re: the regexp comma.
PR to resolve #5521.
Here is how the syntax looks like.
Please note that
scatter
trace would always be added as it is located inlib/core.js
not inlib/index.js
.Also one could use
--unminified
option to create unminified bundles.@plotly/plotly_js